Created
August 25, 2015 06:13
-
-
Save cbfrance/2431ff2525466ef935d7 to your computer and use it in GitHub Desktop.
canvas texture
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
<canvas style="background: red;" width="600px" height="600px"></canvas> | |
<script> | |
var cx = document.querySelector("canvas").getContext("2d"); | |
function branch(length, angle, scale) { | |
cx.fillRect(0, 0, 1, length); | |
if (length < 10) return; | |
cx.save(); | |
cx.translate(0, length); | |
cx.rotate(-angle); | |
branch(length * scale, angle, scale); | |
cx.rotate(2 * angle); | |
branch(length * scale, angle, scale); | |
cx.restore(); | |
} | |
var lengths = ['0.88']; | |
lengths.forEach(function(l) { | |
cx.translate(900, 0); | |
branch(40, 0.8, l); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment