Create a gist now

Instantly share code, notes, and snippets.

nth loop logo processing sketch
color[] colors = { color(85, 98, 112), color(78, 205, 196),
color(199, 244, 100), color(255, 107, 107),
color(196, 77, 88)
};
float rot = 0;
int colorIndex = 0;
void setup() {
frameRate(26);
size(325, 200, P3D);
}
void draw() {
noStroke();
background(255);
// Set up 3 light sources
directionalLight(50, 50, 50, 0, -50, -50);
directionalLight(50, 50, 50, 50, 50, -50);
ambientLight(155, 155, 155);
translate(50, 105, -50);
rotateY(PI/4);
rotateZ(PI/2);
rotateX(PI/4);
// animate by rotating across the z-axis
rot += 0.05;
if (rot >= TWO_PI) {
rot = 0;
}
rotateZ(-rot);
// Start drawing the shape
beginShape(QUAD_STRIP);
// Set up variables for the helix
// x = r.cos(t), y = r.sin(t), z = c.t
// To get a fan-fold, make two helixes of different sizes and
// draw shapes from one to the next.
float c = 75, r = 100, r2 = 150, maxT = 3.2, t, t2;
float x, y, z, factor = 5, i, diff = 10;
colorIndex = 0;
for (i = 0; i < maxT * factor; i++) {
t = i / factor;
t2 = (i + 1) / factor;
fill(colors[(int) colorIndex / 2]);
x = r * cos(t);
y = -r * sin(t);
z = c * t;
vertex(x, y, z);
x = -r * cos(t2);
y = +r * sin(t2);
z = c * t;
vertex(x, y, z);
x = r * cos(t);
y = -r * sin(t);
z = c * t + diff;
vertex(x, y, z);
x = -r * cos(t2);
y = +r * sin(t2);
z = c * t + diff;
vertex(x, y, z);
colorIndex++;
colorIndex = colorIndex % 10;
}
endShape();
fill(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment