Skip to content

Instantly share code, notes, and snippets.

@defHLT
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defHLT/b0d84d4b94a213d94d44 to your computer and use it in GitHub Desktop.
Save defHLT/b0d84d4b94a213d94d44 to your computer and use it in GitHub Desktop.
int W = 1024;
int H = 700;
float K1 = 0.4;
float K2 = 0.6;
float LEN_DEC1 = 0.66;
float LEN_DEC2 = 0.5;
float ANGLE1 = PI/6;
float ANGLE2 = -PI/6;
int STEPS = 14;
void setup() {
size(W, H);
stroke(255);
background(0, 0, 0);
//forkLine(W/2, H-50, 300, PI/2.0, 0);
}
void draw() {
clear();
forkLine(W/2, H-50, 400, (2*mouseX-W)/float(W) + PI/2, 0, int((H-mouseY)/64.0));
}
void forkLine(float x, float y, float len, float deg, int c, int steps) {
//if (c >= steps) return;
if (len < 2) return;
float xd = x - cos(deg) * len;
float yd = y - sin(deg) * len;
line(x, y, xd, yd);
float len1 = len * LEN_DEC1;
float deg1 = deg - ANGLE1 + (2*mouseX-W)/float(W);
float x1 = x - cos(deg) * K1 * len;
float y1 = y - sin(deg) * K1 * len;
forkLine(x1, y1, len1, deg1, c+1, steps);
float len2 = len * LEN_DEC2;
float deg2 = deg - ANGLE2 + (2*mouseX-W)/float(W);
float x2 = x - cos(deg) * K2 * len;
float y2 = y - sin(deg) * K2 * len;
forkLine(x2, y2, len2, deg2, c+1, steps);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment