We are about to switch to a new forum software. Until then we have removed the registration on this forum.
classic question, I know. How can I slow down this sketch? any other suggestions also much appreciated
//Thanks to Richard Carter, Dan Wilcox
//Mandala-like pattern generator
//Mouse click to pause the view
void setup() {
size(666,666);
}
boolean TF=true;
float x;
float y;
int sens=1;
void draw() {
background(255);
for (int i=1; i<333;i+=31) {
for (int j=1; j<333;j+=31) {
noFill();
strokeWeight(1.5);
if (TF) {
x= x + sin (millis() * 0.0014);
y= y + sin (millis() * 0.0014);
}
ellipse(i*2+70,j*2+70,abs(sens*(x-250)),abs(sens*(y-250)));
ellipse(i*2+70,j*2+70,abs(sens*(y-250)),abs(sens*(x-250)));
}
}
}
void mouseClicked() {
TF=!TF;
}
Answers
https://Processing.org/reference/frameRate_.html
try changing the 0.0014 to 0.000014 in lines 22 & 23. This will slow it down by a factor of 100
You could use a variable instead, then vary the speed by changing the variable.
changing the "0.0014" to "0.000014" makes causes the image to expand endlessly and disappear...? and frameRate makes it seems so choppy, but maybe there is no other choice. thank you both
Additionally; any other suggestions for improving this thing?
Reducing the framerate will make the animation more jerky - fact of life.
I was surprised at the other result because the 0.0014 is inside a sin function and continuous expansion shouldn't have happened. Now I have examined your code I realise it is the way you calculate the new x and y position based on their old positions.
I changed lines 22 and 23 to
and the animation is much pretier and smoother with the P2D renderer, change lie 6 to
size(666, 666, P2D);
You can now vary the speed by changing the value of 0.005
Excellent. Thank you very much. This helps me to understand millis() and the P2D makes a great different.
so, this is solved then.