...
Programm a drawing app. The color can be changed with the buttons '1' - '5'. The left mouse button is draws and the right mouse button is used to erase it.
Possible solution to exerciser exercise 5:
Code Block |
---|
color myColor = color(255, 0, 0);// red by default void setup() { size(600, 600); // def. window size noStroke(); background(255); } void draw() { if (mousePressed && mouseButton == LEFT) { fill(myColor); ellipse(mouseX, mouseY, 15, 15); } if (mousePressed && mouseButton == RIGHT) { fill(255); // white ellipse(mouseX, mouseY, 15, 15); } } void keyPressed() { switch(key) { case '1': myColor = color(255, 0, 0);// red break; case '2': myColor = color(0, 255, 0);// green break; case '3': myColor = color(0, 0, 255);// blue break; case '4': myColor = color(0, 0, 0);// black break; case '5': myColor = color(255, 255, 0);// yellow break; default: println("wrong key"); break; } } |
...