We are about to switch to a new forum software. Until then we have removed the registration on this forum.
http://www.learningprocessing.com/examples/chapter-10/example-10-1/
Catcher catcher;
void setup() {
size(400,400);
catcher = new Catcher(32);
smooth();
}
void draw() {
background(255);
catcher.setLocation(mouseX,mouseY);
catcher.display();
}
class Catcher {
float r; // radius
float x,y; // location
Catcher(float tempR) {
r = tempR;
x = 0;
y = 0;
}
void setLocation(float tempX, float tempY) {
x = tempX;
y = tempY;
}
void display() {
stroke(0);
fill(175);
ellipse(x,y,r*2,r*2);
}
}
What's the purpose of this part?
Catcher(float tempR) { r = tempR; ** x = 0; y = 0;** }
Isn't x = mouseX and y = mouseY? As seen on the void setLocation function.
Can't the constructor just be:
Catcher (float tempR){
r = tempR;
}
Answers
You tell us for we only see an underscore followed by a buncha asterisks!!! 8-}
Lol I edited it, and nice to see you. ;)
It's redundant since
float
fields starts out as0.0f
already! ;)So just field r really needs to be initialized! :P
I think the idea of that class is that instead of auto-animate via a method like update(),
it needs to be updated from outside via setLocation() in order to have its fields x & y synchronized!
So it's not much diff. than a regular PVector after all!
In this particular case, the overseer sketch passes the current mouse coods. via setLocation()
to the Catcher instance each frame.
As a bonus, a tweaked version: :ar!