We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have my code set up so that I can draw on my sketch, but I want to use if statements where if clicking within certain perimeters the stroke size and color will change of the brush. I thought that what I had would create that, but it doesn't seem to affect anything. Any help would be appreciated.
Here is the code:
int Yellow;
int Red;
int Green;
int Blue;
int White;
int Black;
void setup()
{
size(600, 600);
background(255);
Yellow = color(255, 255, 0);
Red = color(255, 0, 0);
Green = color(0, 255, 0);
Blue = color(0, 0, 255);
White = color(255);
Black = color(0);
}
//interface
void draw()
{
stroke(1);
smooth();
fill(Yellow);
rect(20, 20, 20, 20);
fill(Red);
rect(50, 20, 20, 20);
fill(Green);
rect(80, 20, 20, 20);
fill(Blue);
rect(110, 20, 20, 20);
fill(255);
rect(140, 20, 20, 20); //the eraser
//stroke size and erase
fill(255);
rect(20, 50, 20, 20);
stroke(2);
line(20, 60, 40, 60);
fill(255);
rect(20, 80, 20, 20);
stroke(4);
line(20, 90, 40, 90);
fill(255);
rect(20, 110, 20, 20);
line(20, 110, 40, 130);
line(40, 110, 20, 130);
}
void mouseDragged()
{
line(pmouseX, pmouseY, mouseX, mouseY);
stroke(1);
fill(255, 0, 0);
}
//here set boundries
{
if (mousePressed)
{
if (mouseY > 20 && mouseY < 40)
{
if (mouseX >20 && mouseX < 40)
{
stroke(Yellow);
}
if (mouseX>50 && mouseX < 70)
{
stroke(Green);
}
if (mouseX>80 && mouseX<100)
{
stroke(Blue);
}
if (mouseX>110 && mouseX<130)
{
stroke(Black);
}
if (mouseX>140 && mouseX<160)
{
stroke(White);
}
}
}
}
Answers
Hmm... This is much alike this recent post:
http://forum.processing.org/two/discussion/2754/how-to-make-the-image-interactive
The code after
//here set boundries
is outside any function, so it won't be run. Perhaps you have missing avoid mousePressed()
before this block (and in this case, there is no need forif (mousePressed)
try this ..