We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Nmaste all, a very basic question, why won't processing increase the value of mouseX in the given code? if i use "mouseX++" instead of "x++" it does increase it
void setup() {
size(600, 600);
background(0);
stroke(255);
fill(255, 10);
}
float a = 0;
void draw() {
float x = mouseX;
float y = mouseY;
point(x, y);
x++;
}
Thanks :)
Answers
Both x & y variables were declared inside function draw():
float x = mouseX, y = mouseY;
Therefore once draw() ends, both x & y cease to exist as well, for their lifespan is scoped to draw(). :-B
But draw will end only if I press the stop button, till then it should keep updating the x,y values which it does, only thing is I think its not running the X++ line? dunno..... I m a bit confused here.
no, draw() is called again and again, automatically. but each call is separate. and variables local to draw() are only available during that one call.
don't change mouseX and mouseY, they are built in and should only be read, not modified.
Function draw() is automatically called back by Processing at about 60 FPS by default!
Therefore, both x & y variables are "born" and "die" at about 60 FPS! @-)
https://Processing.org/reference/draw_.html
Thanks a lot guys I got it now :D