...
Create a program where a unique shape follows the mouse position.
Exercise Solution
Code Block |
---|
color myColor = color(255, 0, 0);
void setup()
{
size(600, 600); // def. output resolution
noStroke();
background(255);
fill(myColor);
}
void draw()
{
if (mouseButton == LEFT) {
fill(myColor);
ellipse(mouseX, mouseY, 20, 20);
} else if (mouseButton == RIGHT) {
fill(255);
ellipse(mouseX, mouseY, 20, 20);
}
}
void keyPressed() {
switch(key)
{
case '1':
println("red");
myColor = color(255, 0, 0);
break;
case '2':
println("green");
myColor = color(0, 255, 0);
break;
case '3':
println("blue");
myColor = color(0, 0, 255);
break;
case '4':
println("yellow");
myColor = color(255, 255, 0);
break;
case '5':
println("black");
myColor = color(0);
break;
default:
println("wrong key");
break;
}
}
|