Skip to content

Instantly share code, notes, and snippets.

@valexey
Created September 4, 2013 23:33
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 valexey/6444226 to your computer and use it in GitHub Desktop.
Save valexey/6444226 to your computer and use it in GitHub Desktop.
js processing tree demo
(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