Created
March 14, 2019 19:13
-
-
Save martoo6/0bc9ad44727739ce6b1b23c88083a263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final int frames = 60; | |
void setup(){ | |
size(500,500,P3D); | |
background(0); | |
noFill(); | |
stroke(255); | |
strokeWeight(2); | |
} | |
void draw(){ | |
background(0); | |
final int fc = frameCount; | |
//Time goes form 0 to 1 so is easy to loop !! | |
final float t = map(fc, 0, frames, 0, 1) % 1; | |
pushMatrix(); | |
translate(width/2, height/2, -50); | |
final int boxes = 8; | |
final float step = TWO_PI/boxes; | |
final float radius = 200; | |
//Draw a perfect circle | |
for(int i=0;i<boxes;i++){ | |
final float x = sin(i*step)*radius; | |
final float y = cos(i*step)*radius; | |
drawCube(t, x, y, 0); | |
} | |
popMatrix(); | |
} | |
void drawCube(float t, float destX, float destY, float destZ){ | |
//Sin goes from -1 to 1 and loops perfectly thanks to "t" | |
final float sinT = sin(t*TWO_PI); | |
float x = map(sinT, -1, 1, 0, destX); | |
float y = map(sinT, -1, 1, 0, destY); | |
float z = map(sinT, -1, 1, 0, destZ); | |
pushMatrix(); | |
translate(x, y, z); | |
//Rotate in all axis and loop thans to "t" !! | |
rotateX(t*TWO_PI); | |
rotateY(t*TWO_PI); | |
rotateZ(t*TWO_PI); | |
box(50); | |
popMatrix(); | |
} |
Author
martoo6
commented
May 18, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment