We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have got to this point, using help from this post https://forum.processing.org/two/discussion/20148/beginner-question-how-to-change-color-of-the-ellipse-everytime-the-mouse-is-pressed
and have changed it a bit to get the following:
color[] colours = new color[3]; int c = 0;
void setup() { size(500, 500); colours[0] = color(255, 0, 0); colours[1] = color(0, 255, 0); colours[2] = color(0, 0, 255); }
void draw() { if (mousePressed == true && (mouseButton == LEFT)) {
fill(colours[c]);
ellipse(mouseX, mouseY, 50, 50);
c = (c + 1) % 3;
} }
However, when I click the left mouse button, it continuously displays circles until the mouse click is released. Instead I wish it to display one circle of one colour per click. I.E. 1st click = red circle at mouse coordinates, release mouse click 2nd click = green circle at mouse coordinates, release mouse click 3rd click = blue circle at mouse coordinates, release mouse click 4th click = returns to red circle, release mouse click And so on...
How would I go about doing this?
Thanks for any help.
Answers
Instead of using mousePressed as a variable use mousePressed () as a function
See reference. The function is indicated by the brackets ()
The function registers mouse clicks only once but the variable registers them throughout, often
I just tried to do that but I made a mess of it. Sorry, I am relatively new. How would I do that? Is it changing it back to how the post I linked had it?
Thanks
A function is a section from
{
to}
.You have functions
setup()
anddraw()
now.As shown in the reference make a new function
mousePressed()
afterdraw() {.....}
:Then check your brackets
{ }
You can save with a new name then you have two distinct versions of your sketch
That worked. Thank you very much!
;-)