Skip to content

Instantly share code, notes, and snippets.

@becojo
Created January 9, 2014 23:34
Show Gist options
  • Save becojo/8344190 to your computer and use it in GitHub Desktop.
Save becojo/8344190 to your computer and use it in GitHub Desktop.
import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;
// defines the number of sides of the polygon
int sides = 6;
// the radius of the polygon
int radius = 180;
// the inner angle of the polygon
float angle = TWO_PI / sides;
// easing equation to use for the animation
Easing easing = Ani.QUINT_IN_OUT;
// the points used to create the links
PVector[] points = new PVector[(sides * (sides - 1)) / 2];
// colors of each set of links
color[] colors = new color[points.length];
// color schemes
color[][] themes = new color[][] {
{ #00b6e9, #00e970 }, // blue/green-ish
{ #EC3E15, #ECDE15 }, // red/orang-ish
{ #ff00ff, #00ffff } // mangenta/cyan
};
// which color scheme to use
int theme = 1;
// animation duration
float duration = 1.0;
// save frames?
boolean record = false;
void setup() {
size(500, 500);
strokeWeight(5);
Ani.init(this);
float a, b, delay;
int n, m, index = 0;
// for each sides of the polygon
for(n = 0; n < sides; n++) {
// for each possible links
for(m = 1; m <= n; m++) {
// begining angle
a = angle * n - HALF_PI;
// targeted angle
b = a - m * angle;
// initialize points at the polygons corners
points[index] = new PVector(cos(a) * radius, sin(a) * radius);
// animation delay
delay = (sides - n - 1) * 0.2;
// Ani.to(object, duration, delay, property, target value, easing equation)
Ani.to(points[index], duration, delay, "x", cos(b) * radius, easing);
Ani.to(points[index], duration, delay, "y", sin(b) * radius, easing);
index++;
}
// stores the colors colors of each links
colors[n] = lerpColor(themes[theme][0], themes[theme][1], float(n) / sides);
}
}
void draw() {
background(245);
translate(width / 2, height / 2);
int n, m, index;
float x, y, a;
index = 0;
for(n = 0; n < sides; n++) {
a = angle * n - HALF_PI;
x = cos(a) * radius;
y = sin(a) * radius;
noStroke();
fill(colors[n]);
ellipse(x, y, 5, 5);
stroke(colors[n]);
for(m = 0; m < n; m++) {
line(x, y, points[index].x, points[index].y);
index++;
}
}
if(record) {
saveFrame(String.format("polygon%d-%d-%d-#####.png", sides, radius, theme));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment