We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to make a function which can be called to draw multiple circles rotating at different directions and with variable radii. The problem is that the circle's X and Y positions don't change, I've tried removing the code from the function and just placing it in the main and it works fine. (after i declare the variables of course). side question: why is the radius of rotation not equal the variable r? i'm assuming it has something to with the rate of change of the cos(inc)/sin(inc), but i'm not sure what exactly the relation is. here it is:
void setup ()
{size(500,500);
}
void draw ()
{
background(255);
circle(250,20,10,0.1,0.1);
}
void circle(float x,float y, float r, float pos, float step)
{
fill(0);
ellipse(x,y,25,25);
x+=r*cos(pos);
y+=r*sin(pos);
pos+=step;
}
Answers
draw() runs 60 times per second
you give x and y as a parameter to the function and thus the old x and y are overwritten (or in fact forgotten since they only exist while the function circle runs: They are as parameters only locale variables)
you could define those variables with a global scope (at sketch level). Thus the changes would remain permanent.
[EDITED] you also mixed up the formula a bit - I corrected that now. (making what I said before mainly invalid except for pos)
;-)
I think I got it :D, thank you.