Created
December 10, 2015 17:26
-
-
Save jacobjoaquin/4d9386ee10ada9618c16 to your computer and use it in GitHub Desktop.
Recursive Animated Pentagon in Orange
This file contains hidden or 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
class RecShape { | |
ArrayList<PVector> points; | |
RecShape() { | |
points = new ArrayList<PVector>(); | |
} | |
RecShape(ArrayList<PVector> copiedPoints) { | |
points = new ArrayList<PVector>(); | |
for (PVector p : copiedPoints) { | |
points.add(p.get()); | |
} | |
} | |
void add(float x, float y) { | |
add(new PVector(x, y)); | |
} | |
void add(PVector p) { | |
points.add(p); | |
} | |
void display() { | |
beginShape(); | |
for (PVector p : points) { | |
vertex(p.x, p.y); | |
} | |
endShape(CLOSE); | |
} | |
RecShape spawn(float offset) { | |
RecShape shape = new RecShape(); | |
int s = points.size(); | |
for (int i = 0; i < s; i++) { | |
PVector p0 = points.get(i); | |
PVector p1 = points.get((i + 1) % s); | |
shape.add(lerp(p0.x, p1.x, offset), lerp(p0.y, p1.y, offset)); | |
} | |
return shape; | |
} | |
} |
This file contains hidden or 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
int nPoints = 5; | |
int nSpawns = 1000; | |
float theSize; | |
int scale = 1; | |
int nFrames = 100; | |
float phase = 0.0; | |
float phaseInc = 1 / (float) nFrames; | |
void settings() { | |
size(500 * scale, 500 * scale, P2D); | |
} | |
void setup() { | |
blendMode(ADD); | |
noFill(); | |
stroke(212, 128, 32, 128); | |
theSize = width; | |
frameRate(30); | |
} | |
float foo = 0; | |
void draw() { | |
background(0); | |
RecShape shape = new RecShape(); | |
for (int i = 0; i < nPoints; i++) { | |
float n = i / (float) nPoints; | |
PVector p = PVector.fromAngle(n * TAU); | |
p.mult(500); | |
p.add(width / 2.0, height / 2.0); | |
shape.add(p); | |
} | |
shape.display(); | |
float nPhase = phase; | |
for (int i = 0; i < nSpawns; i++) { | |
RecShape shape2 = shape.spawn(nPhase); | |
nPhase += 0.01; | |
nPhase -= (int) nPhase; | |
shape2.display(); | |
shape = shape2; | |
} | |
phase += phaseInc; | |
phase -= (int) phase; | |
//saveFrame("tiff/f######.tiff"); | |
//if (frameCount == nFrames) { | |
// exit(); | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment