Created
September 4, 2013 23:33
-
-
Save valexey/6444226 to your computer and use it in GitHub Desktop.
js processing tree demo
This file contains 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
(function ($p) { | |
var theta = 0; | |
function setup() { | |
$p.size(640, 360); | |
} | |
$p.setup = setup; | |
function draw() { | |
$p.background(0); | |
$p.frameRate(30); | |
$p.stroke(255); | |
var a = ($p.mouseX / $p.width) * 90; | |
theta = $p.radians(a); | |
$p.translate($p.width / 2, $p.height); | |
$p.line(0, 0, 0, -120); | |
$p.translate(0, -120); | |
branch(120); | |
} | |
$p.draw = draw; | |
function branch(h) { | |
h *= 0.66; | |
if (h > 2) { | |
$p.pushMatrix(); | |
$p.rotate(theta); | |
$p.line(0, 0, 0, -h); | |
$p.translate(0, -h); | |
branch(h); | |
$p.popMatrix(); | |
$p.pushMatrix(); | |
$p.rotate(-theta); | |
$p.line(0, 0, 0, -h); | |
$p.translate(0, -h); | |
branch(h); | |
$p.popMatrix(); | |
} | |
} | |
$p.branch = branch; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment