I can't solve a simple problem with two variables and the fill() instruction.
in
Programming Questions
•
1 year ago
Hello!
I am trying to build this little program to make a simple "paint" application for a course I am taking.
As I click on the erase button, it works properly, but when I click on the draw button again, the color selected before won't come back.
This property should be controlled by the two variables, markerColor and previousColor.
Please forgive the dull coding, I am just starting.
I would really appreciate any help.
Regards
_____________________________________________________________________________-
PImage ribbon;
int markerRadius=10;
color markerColor=color(128,128,128);
color previousColor=color(128,128,128);
float markerRed=128;
float markerGreen=128;
float markerBlue=128;
void setup() {
size(1024, 768);
frameRate(120);
background(255);
ribbon = loadImage("ribbon03.png");
image(ribbon, 2, 2);
smooth();
noStroke();
fill(markerColor);
rect(648,17,51,65);
}
void draw() {
// MARK
if (mouseY<100){
if(mouseY>14&&mouseY<84){
if(mouseX>16&&mouseX<59){
if(mousePressed){
markerColor=previousColor;
fill(markerColor);
rect(648,17,51,65);
}
}
// ERASE
if(mouseX>84&&mouseX<107){
if(mousePressed){
previousColor=markerColor;
markerColor=color(255,255,255);
fill(markerColor);
rect(648,17,51,65);
}
}
}
// MARKER RADIOUS
if(mouseY>11&&mouseY<92){
if(mouseX>133&&mouseX<152){
if(mousePressed){
markerRadius=50;
}
}
if(mouseX>156&&mouseX<173){
if(mousePressed){
markerRadius=45;
}
}
if(mouseX>179&&mouseX<195){
if(mousePressed){
markerRadius=40;
}
}
if(mouseX>203&&mouseX<216){
if(mousePressed){
markerRadius=35;
}
}
if(mouseX>226&&mouseX<238){
if(mousePressed){
markerRadius=30;
}
}
if(mouseX>249&&mouseX<259){
if(mousePressed){
markerRadius=25;
}
}
if(mouseX>272&&mouseX<281){
if(mousePressed){
markerRadius=20;
}
}
if(mouseX>295&&mouseX<302){
if(mousePressed){
markerRadius=15;
}
}
if(mouseX>319&&mouseX<324){
if(mousePressed){
markerRadius=10;
}
}
if(mouseX>342&&mouseX<345){
if(mousePressed){
markerRadius=05;
}
}
}
//BLACK AND WHITE
if(mouseX>373&&mouseX<400){
if(mouseY>016&&mouseY<043){
if(mousePressed){
previousColor=markerColor;
markerColor=color(0,0,0);
fill(markerColor);
rect(648,17,51,65);
}
}
if(mouseY>55&&mouseY<82){
if(mousePressed){
previousColor=markerColor;
markerColor=color(255,255,255);
fill(markerColor);
rect(648,17,51,65);
}
}
}
//SHADES OF GRAY
if((mouseY>16&&mouseY<83)&&(mouseX>413&&mouseX<438)){
if(mousePressed){
previousColor=markerColor;
markerColor=get(mouseX,mouseY);
fill(markerColor);
rect(648,17,51,65);
}
}
//WATER COLOR
if((mouseY>17&&mouseY<84)&&(mouseX>452&&mouseX<570)){
if(mousePressed){
previousColor=markerColor;
markerColor=get(mouseX,mouseY);
fill(markerColor);
rect(648,17,51,65);
}
}
//RGB BUTTONS
//R
if(mouseY>15&&mouseY<38){
if(mouseX>586&&mouseX<614){
if(mousePressed){
markerRed=red(markerColor);
markerRed++;
if(markerRed>255){
markerRed=255;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
if(mouseX>615&&mouseX<637){
if(mousePressed){
markerRed=red(markerColor);
markerRed--;
if(markerRed<0){
markerRed=0;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
}
//G
if(mouseY>39&&mouseY<61){
if(mouseX>586&&mouseX<614){
if(mousePressed){
markerGreen=green(markerColor);
markerGreen++;
if(markerGreen>255){
markerGreen=255;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
if(mouseX>615&&mouseX<637){
if(mousePressed){
markerGreen=green(markerColor);
markerGreen--;
if(markerGreen<0){
markerGreen=0;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
}
//B
if(mouseY>62&&mouseY<84){
if(mouseX>586&&mouseX<614){
if(mousePressed){
markerBlue=blue(markerColor);
markerBlue++;
if(markerBlue>255){
markerBlue=255;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
if(mouseX>615&&mouseX<637){
if(mousePressed){
markerBlue=blue(markerColor);
markerBlue--;
if(markerBlue<0){
markerBlue=0;
}
previousColor=markerColor;
markerColor=color(markerRed,markerGreen,markerBlue);
fill(markerColor);
rect(648,17,51,65);
}
}
}
//CLEAR CANVAS
if((mouseX>726&&mouseX<829)&&(mouseY>11&&mouseY<91)){
if(mousePressed){
fill(255,255,255);
rect(0,0,1024,768);
}
}
}
fill(markerColor);
if(mousePressed&&mouseY>100){
ellipse(mouseX,mouseY,markerRadius,markerRadius);
}
image(ribbon, 2, 2);
}
// ICONS LIMITS OF THE RIBBON
// Ribbon Height 100
// y 14 to 84
// x 16 to 59 draw
// x 64 to 107 erase
// y 11 to 92
// x 133 to 152 width 10
// x 156 to 173 width 9
// x 179 to 195 width 8
// x 203 to 216 width 7
// x 226 to 238 width 6
// x 249 to 259 width 5
// x 272 to 281 width 4
// x 295 to 302 width 3
// x 319 to 324 width 2
// x 342 to 345 width 1
// y 16 to 43 black
// y 55 to 82 white
// x 373 to 400
// y 16 to 83
// x 413 to 438 grays
// y 17 to 84
// x 452 to 570 watercolor
// y 16 to 38 r
// y 39 to 61 g
// y 62 to 84 b
// x 586 to 614 +
// x 615 to 637 -
// y 17 to 82
// x 648 to 699 color display
// y 11 to 91
// x 726 to 829 erase all
1