The values in x and y change after setting the px and py values. The "= operator" when acting on primitive data types like float and int, will change the value of the memory address associated with the identifier. When you set variables equal to each other you take everything on the right and pack it in to the variable on the left of the = symbol.
its not identical where it gets printed. the idea is to have the current x,y value and the previous one, thats why its called px,py... so they are the same at the beginning, but right after that x,y gets changed. then they use x and px to calculate the distance between the position and the previous one to get the circle size and make them touch each other...
regarding your second question, there is no reason not to use mouseX and mouseY instead of targetX,Y... maybe easier to read thats why...
1. Yes, for a moment after line 16 py and y are identical, as are px and x. But on line 18 x gets a new value and y gets a new value on line 20 - these new values are based on the mouse location. On line 21 the routine is comparing where x and y are now (after the changes) to where they were the last time the draw routine was run. Don't forget the draw is constantly looping. When I write these I usually set px = x and py = y at the end of the routine rather than the start - helps me get my head around it - but this way works just as well. I use the variable names px and py too, but I think of them a "previous x" and "previous y".
2. Good question. As it stands there's no reason and you could use the mouseX and mouseY, however, the author may be thinking of using these values in a larger sketch down the road at which point having a separate variable might be handy. That's the only (slightly lame) rason I can think of.
Have fun with the processing.
Leave a comment on joester5's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic