Created
January 23, 2014 14:20
-
-
Save anonymous/8579205 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<style> | |
canvas { border: 1px lightgray solid; } | |
body { margin: 0; } | |
</style> | |
</head> | |
<body> | |
<canvas id="drawing" width="600" height="600"></canvas> | |
</body> | |
</html> |
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
var canvas = document.getElementById('drawing'); | |
var c = canvas.getContext("2d"); | |
function phi_evolution(phi) { | |
return phi + (Math.random() - 0.5) * (phi / 2.0); | |
} | |
function plus_minus() { | |
return Math.random() < 0.5 ? -1 : 1; | |
} | |
function color(initial) { | |
return '#'+Math.floor(16777215/(initial * Math.random())).toString(16); | |
} | |
function branch(len, ratio, rotate, phi) { | |
c.beginPath(); | |
c.lineWidth = len / 10; | |
c.rotate(Math.PI * rotate / 180.0); | |
c.moveTo(0, 0); | |
c.lineTo(0, -len); | |
c.strokeStyle = color(len * 0.2); | |
c.stroke(); | |
c.translate(0, -len); | |
if (len > 5) { | |
for (var i = len; i < 0; i--) { | |
c.save(); | |
branch(len * ratio, ratio, rotate + phi * plus_minus(), phi_evolution(phi)); | |
c.restore(); | |
branch(len * ratio, ratio, rotate + phi * plus_minus(), phi_evolution(phi)); | |
} | |
} | |
} | |
c.translate(300, 590); | |
branch(100, 0.8, 0, 8); | |
//c.setTransform(1, 0, 0, 1, 0, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment