Why doesn't this code work...
in
Programming Questions
•
23 days ago
The goal is to create a code that allows you to choose the color of a shape (in this case an ellipse, and using red,green,and blue) by using keyPressed, and then to be able to click on the screen and have an ellipse show up in a random part of the screen. Everything is working except for the color selector(i.e. the keyPressed function).
int r;
int g;
int b;
int x;
int y;
void setup(){
size(600,600);
background(251,255,49);
}
void draw() {
}
void keyPressed() {
println(key);
switch(key) {
case 'r':
case 'R':
r = 255;
g = 0;
b = 0;
break;
case 'g':
case 'G':
r = 0;
g = 255;
b = 0;
break;
case 'b':
case 'B':
r = 0;
g = 0;
b = 255;
break;
default:
break;
}
}
void drawShape(int x, int y){
ellipse(x,y,25,25);
}
int r;
int g;
int b;
int x;
int y;
void setup(){
size(600,600);
background(251,255,49);
}
void draw() {
}
void keyPressed() {
println(key);
switch(key) {
case 'r':
case 'R':
r = 255;
g = 0;
b = 0;
break;
case 'g':
case 'G':
r = 0;
g = 255;
b = 0;
break;
case 'b':
case 'B':
r = 0;
g = 0;
b = 255;
break;
default:
break;
}
}
void drawShape(int x, int y){
ellipse(x,y,25,25);
}
1