Created
June 11, 2018 14:29
-
-
Save avdotion/1c08af1d2d479a3b65fda4ed8099de1a to your computer and use it in GitHub Desktop.
Fractal Trees - Recursive (p5.js)
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
const maxRecurtionDepth = 15; | |
let slider, angle; | |
const len = 200; | |
function setup() { | |
createCanvas(600, 600); | |
slider = createSlider(0, PI, PI/4, PI/16); | |
} | |
function draw() { | |
background(51); | |
angle = slider.value(); | |
stroke(255); | |
translate(width/2, height); | |
branch(len, maxRecurtionDepth); | |
} | |
function branch(len, depth) { | |
if (depth > 0) { | |
line(0, 0, 0, -len); | |
translate(0, -len); | |
push(); | |
rotate(angle); | |
branch(len * 2 / 3, depth - 1); | |
pop(); | |
push(); | |
rotate(-angle); | |
branch(len * 2 / 3, depth - 1); | |
pop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment