Created
March 8, 2017 05:50
-
-
Save tanishiking/5473aed5aafb1ec84eff5dcf31df9d7e to your computer and use it in GitHub Desktop.
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
void setup() { | |
size(3035, 4299); | |
} | |
void draw() { | |
float degree = 30.0; | |
float theta = radians(degree); | |
float initialHeight = 500.0; | |
float weight = 50.0; | |
int count = 14; | |
frameRate(0.5); | |
background(111, 174, 188); | |
stroke(255, 255, 255); | |
translate(width/2, height); | |
strokeWeight(weight); | |
line(0, 0, 0, -initialHeight); | |
translate(0, -initialHeight); | |
branch(initialHeight, theta, count, weight); | |
strokeWeight(weight * 0.9); | |
line(0, 0, 0, -initialHeight); | |
translate(0, -initialHeight); | |
branch(initialHeight, theta, count, weight * 0.9); | |
strokeWeight(weight * 0.8); | |
line(0, 0, 0, -initialHeight); | |
translate(0, -initialHeight); | |
branch(initialHeight, theta, count, weight * 0.8); | |
// saveFrame("tree-#####.jpg"); | |
} | |
private void branch(float h, float theta, int count, float weight) { | |
float branchHeightScale = 0.90; | |
float weightScale = 0.7; | |
float thetaScale = 0.85; | |
h *= branchHeightScale; | |
weight *= weightScale; | |
if (count > 0) { | |
pushMatrix(); | |
grow(h * random(0.0, 1.0), randomGaussian() * theta * thetaScale, weight); | |
branch(h, theta, count - 1, weight); | |
popMatrix(); | |
pushMatrix(); | |
grow(h * random(0.0, 1.0), randomGaussian() * theta * thetaScale, weight); | |
branch(h, theta, count - 1, weight); | |
popMatrix(); | |
} | |
} | |
private void grow(float h, float theta, float weight) { | |
rotate(theta); | |
strokeWeight(weight); | |
line(0, 0, 0, -h); | |
translate(0, -h); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment