We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. i am having a problem with my code. with the code below, i am unable to get anything to happen on right and left mouse clicks. any ideas as to why? i am perplexed, any hints would be amazing
void setup(){ size(1800, 720); background(255); } void draw(){ ellipse(mouseX, mouseY, 25, 25); if((mousePressed) && (mouseButton == LEFT)){ float a = random(1, 255); float b = random(1, 255); float c = random(1, 255); fill(a, b, c); }if ((mousePressed) && (mouseButton == RIGHT)){ fill(255); stroke(0); noStroke(); }else { noFill(); noStroke(); } }
Answers
This is what your code says:
1) Start with a white background.
2) Draw a circle (using the colors set in the last frame).
3) When the next frame draws, the circle will be:
4) A random color if the left button was pressed.
5) Actually wait, forget about whatever we said in step (4). If the right button was pressed, it should be white, and if not, it should be clear.
So when the circle is drawn the next frame, on a white background, it is either white or see-through! SO YOU DON'T SEE IT!
This is what (I think) you want your code to do:
1) Start with a white background.
2) If the mouse is pressed, do steps 3, 4, and 5. Otherwise stop here.
3) If it's the left mouse button, set the draw color to random.
4) If it's the right mouse, set the draw color to white.
5) Draw a circle.
This is what that code looks like. Notice the nestled if statements. Also notice that the circle is now drawn AFTER the fill color is set.