We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. I got a prinsipal mistake of making code. Please tell me, why i cant make animation with this code? I`ve got on the screen only the last loop realization.
float[] x = new float[36000];
float[] y = new float[36000];
float rad = 450;
void setup()
{
size(1000,1000);
translate (500,500);
for (int i = 0 ; i < 36000 ; i ++)
{
x[i] = cos(radians(i)) * rad;
println(x[i]);
y[i] = sin(radians(i)) * rad;
point (x[i] , y[i]);
//line (x[i] , y[i] , x[i+1] , y[i+1] );
}
}
void draw()
{
background(0);
translate (500,500);
//rotate(0.95);
for (int n = 0; n <= 2; n = n + 1)
{
cardio (n);
//delay(100);
}
}
void cardio (int n)
{
background(0);
for (int i = 0; i < 360; i++)
{
//point (y[i]+10 , x[i] + 10);
// x[i] = c;
//line (0 , 0 , c , c );
stroke(204, 102, 0);
line (x[i] , y[i] , x[i * n] , y[i * n ] );
}
}
Answers
The screen only updates at the end of draw(). You don't need a for loop in draw() to do the 100 different images - draw() itself is the loop that you want.
Here's a working version with a few other fixes, like adding a delay:
Yet one question please: what does 24 line (n%=100;) mean? I commented it, and code working =).
Thanks!
n%=100 means "subtract 100 from n until n is less than 100". This makes sure that the value of n stays between 0 and 100 (without equaling 100).
Hmm... Isn't that explanation too abstract? Operator modulo
%
is the remainder of a division: ~O)https://Processing.org/reference/modulo.html
Meh. Same thing.