We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have to write a processing program which responds to a left mouseclick only. It's quite simple actually, the background hast to be red, if I click with my mouse the background has to turn green and when I click again it has to turn blue. And then again red etc. I am stuck at the point where I have to make a difference between the mouse clicks, like first mouse click second mouse click. I saw some examples on the internet but those weren't just with the left mousebutton only.
And should I use an void mousePressed() or not at all ?
I hope someone can give me some good directions.
Answers
@GoToLoop great this is exactly what I was looking for, but could you perhaps explain your code with comments? I find it quite a hard code, I don't understand everything. And since it is a school assignment, I should be able to explain what 'wrote'
The code is about 20 lines only. It'd be easier if you could point out exactly what you don't get it. :\">
You can check in this link: https://processing.org/reference/ as it will answer most of your questions.
Kf
@GoToLoop yes ofcourse you're right, my bad.
It's quite a lot as you can see, I'm really in the beginning of processing. I have a lot discover, so if you think I should be able to figure some lines out myself, I understand that. But I hope you can help me understand this, because I think this a very nice and small program.
1/2 != 1/2.
evaluates astrue
for Java and asfalse
for JS, b/c for the former, the result of a division operation when both operands are integers, the decimal part is removed.static
isn't instantiated when it'sclass
is instantiated: https://Processing.org/reference/static.htmlWeb-color RGB notation https://Processing.org/reference/color_datatype.html
Field idx represents the current index of the PALETTE array.
Field PALETTE was clearly declared as
color[]
datatype at the top of the sketch, right?See
[]
array access: https://Processing.org/reference/arrayaccess.html+
.Operator
%
is called modulo or remainder of a division operation:https://Processing.org/reference/modulo.html
Given the remainder value never reaches the divisor value, instead the remainder cycles back to
0
, it is a nice trick to constrain the current index to always stay within an array's valid range length . :ar!@GoToLoop you are absolutely amazing, thank you very much for explaining everything to me ! I understand your code much better now