Some changes
/* This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int x= 10;
int y=10;
int w=20; //rect width
int h=10; //rect height
boolean button = false;
void setup (){
size (275,100);
background (240, 240, 240);
}
void draw (){
stroke (0);
fill (255,0,0);
rect (x,y,w,h); // red button
fill (0,255,0);
rect (40,y,w,h); //green button
fill (0,0,255);
rect (70,y,w,h); //blue button
noFill();
stroke (0);
if (button){
fill (255, 0,0);
}else{
fill (255, 0,0);
}
stroke (0);
}
void mousePressed (){
if (mouseX>x && mouseX<x+w && mouseY>y &&mouseY<y+h && mousePressed){
println ("RGB color 255,0,0"); // RGB code for the red button
noStroke();
colorMode(RGB, 255);
for (int i=0; i < 255; i++) {
fill(i, 0, 0);
rect(i+10, y+y+y,1, 50); //black to red
}
} else if(mouseX>40 && mouseX<60 && mouseY>y &&mouseY<y+h && mousePressed){
println ("RGB color 0,255,0"); //RGB code for the green button
noStroke();
colorMode(RGB, 255);
for (int i = 0; i < 255; i++) {
fill(0, i, 0);
rect(i+10, y+y+y,1, 50); //black to green
}
} else if (mouseX>70 && mouseX<90 && mouseY>y &&mouseY<y+h && mousePressed){
println ("RGB color 0,0,255"); //RGB code for the blue button
noStroke();
colorMode(RGB, 255);
for (int i = 0; i < 255; i++) {
fill(0, 0, i);
rect(i+10, y+y+y,1, 50); //black to blue
}
}
}