We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, the following Code should be a small paint programm. My Problem is that I can't change the color and I don't know where the fault is. It would be great if somebody can help me! Thankyou and sorry for my bad english! Hallo111
int r=0;
int g=0;
int b=0;
void setup(){
size(760,300);
background(255,255,255);
smooth();
noStroke();
fill(#808080);
rect(0,0,100,300);
stroke(0,0,0);
fill(255,255,255);
ellipse(25,25,30,30);
fill(0,0,0);
ellipse(75,40,30,30);
fill(227,32,32);
ellipse(25,75,30,30);
fill(218,222,36);
ellipse(75,90,30,30);
fill(36,139,222);
ellipse(25,125,30,30);
}
void draw(){
if (mousePressed==true && mouseX>10 && mouseX<40 && mouseY>10 && mouseY<40){
int r=255; int g=255; int b=255;
println("white");
}
if (mousePressed==true && mouseX>60 && mouseX<90 && mouseY>25 && mouseY<55){
int r=0; int g=0; int b=0;
println("black");
}
if (mousePressed==true && mouseX>10 && mouseX<40 && mouseY>60 && mouseY<90){
int r=227; int g=32; int b=32;
println("red");
}
if (mousePressed==true && mouseX>60 && mouseX<90 && mouseY>75 && mouseY<105){
int r=218; int g=222; int b=36;
println("yellow");
}
if (mousePressed==true && mouseX>10 && mouseX<40 && mouseY>110 && mouseY<140){
int r=36; int g=139; int b=222;
println("blue");
}
if (mousePressed==true && mouseX>100 && mouseX<760 && mouseY>0 && mouseY<300){
fill(r,g,b);
noStroke();
ellipse(mouseX,mouseY,30,30);
}
}
Answers
Inside all of those mousePressed conditionals you are doing:
int r=255… etc.
This makes a temporary integer r and does not overwrite the r that you want. Instead do:
r=255… etc.
Yes, that's the solution! Thankyou