Loading...
Logo
Processing Forum

As title, what i want to realize with Processing:

There are classical circles running across on the screen, then:

the first time you click the mouse,all the circles freeze(stop moving);

the second time you click the mouse, you draw a new circle with your mouse position.

Okay now is the problem: how to tell the computer to act differently? After all, they are all clicks, seem the same to the computer.

Does anybody know? Thank you very much.

Replies(4)

Do you want the functionality to switch back and forth?  Or just the first time it freezes, and every subsequent click adds a circle?

I'd try something like this:

Copy code
  1. boolean freezeOnClick = true
  2. if (mousePressed) {
  3.       if (mouseButton == LEFT) {
  4.             if (freezeOnClick) {
  5.                   //freeze the sketch
  6.                   freezeOnClick = !freezeOnClick;
  7.             }
  8.             else {
  9.                   ellipse(mouseX,mouseY,10,10)
  10.             }
  11.       }
  12. }
The first time you click, freezeOnClick is true, and the image freezes and switches the boolean.  After the initial click, the boolean is false so you will always create new circles.

You can alternate between the two functions by including a freezeOnClick = !freezeOnClick statement in the else() loop.
" After all, they are all clicks, seem the same to the computer."
Yes, but in computing, we can have states. Ie. the computer (actually, the program) can remember the state it was on a first click, change this state, check it, and so on.

asymptoticdesign shown a good example with a boolean toogle. You can also have counters, etc.
Thank you sooooooooooo much.
But now i have another problem: how to freeze the circles??

creating art with processing
You freeze a shape... by not moving it!
Instead of using mouseX/Y, use your own variables. Assign them mouseX/Y when you want them to move, stop assigning when you want them frozen.