Hi All.
Is it possible to do this kind of animation smoothly with code in p5.js
Thanks for any help.
Hi All.
Is it possible to do this kind of animation smoothly with code in p5.js
Thanks for any help.
Hello @JoseRocha
Some additional clarification is needed.
You’ve tagged this as “processing”, but your question is “p5.js”.
Can you show your code so we know what you have attempted so far?
Hello @debxyz,
New to this hole thing.
function setup() {
createCanvas(600, 600);
}
function draw() {
background(0);
noFill();
strokeWeight(4);
stroke(255);
for (let i = 0; i < 400; i++){
circle (300, 300, 30 + i);
}
}
Not working at all.
Thanks
Hello @JoseRocha
See comments next to relevant lines for explanation.
let grow = 1;
function setup() {
createCanvas(600, 600);
}
function draw() {
background(0);
noFill();
strokeWeight(4);
stroke(255);
for (let i = 0; i < 3; i++){ //use for loop to count the number of circles you want
if (i == 0){//depending on iteration of "i", set starting circle size
s = 0;
} else if (i == 1){
s = 30;
} else {
s = 60;
}
circle (300, 300, s+grow);
grow+=1; //grow variable increases by 1 with each draw loop, creating the animation
}
}
Hope this helps!
Hello @JoseRocha ,
Yes it is!
I often use frameCount (or you can use a counter) and the modulo % operator.
Consider this for the circle size in your draw():
let r1 = frameCount%360;
let r2 = (frameCount+60)%360;
You may want to print values to console to see change in variables over time.
Add a few more circles and voila!
This animates nicely and is very smooth!
:)
Hi @glv
Thanks for the tip.