Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Last active November 6, 2018 09:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanorelli/8100924 to your computer and use it in GitHub Desktop.
Save jordanorelli/8100924 to your computer and use it in GitHub Desktop.
float rectSize = 30;
int numRects = 40;
float outerRadius = 120;
int aframes = 140;
boolean SAVE_FRAMES = true;
void setup() {
size(500, 500);
}
void draw() {
background(255);
drawRects(numRects);
export();
}
void export() {
if (!SAVE_FRAMES) {
return;
}
if (frameCount > aframes) {
return;
}
String fname = nf((frameCount), 3) + ".png";
println(fname);
save(fname);
}
void drawRects(int numRects) {
for (int i = 0; i < numRects; i++) {
drawRect(i, numRects);
}
}
void drawRect(int i, int numRects) {
float n = norm(i, 0, numRects);
float offset = 80.0 * sin((5 * TWO_PI * n) + (TWO_PI * norm(frameCount%aframes, 0, aframes)));
pushMatrix();
translate(width*0.5, height*0.5);
rotate(n*TWO_PI);
translate(outerRadius+offset, 0);
drawRect();
popMatrix();
stroke(255, 0, 0);
}
void drawRect() {
stroke(0);
strokeWeight(2);
fill(255);
rectMode(CENTER);
rect(0, 0, rectSize, rectSize, 6);
}
@jordanorelli
Copy link
Author

run with SAVE_FRAMES set to true, and then exec convert -delay 2 -size 500x500 -colors 4 -loop 0 *.png out.gif inside of the sketch folder to convert to an animated gif. requires imagemagick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment