Created
December 30, 2018 08:34
-
-
Save akella/d6fb898aa30696b3d011725061dd7ea4 to your computer and use it in GitHub Desktop.
snowflake
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
let maxLevel = 2; | |
let branches = 2; | |
can.width = 500; | |
can.height = 500; | |
let angle = 0.3; | |
ctx.translate(can.width / 2, can.height / 2); | |
function go(){ | |
angle += 0.001; | |
ctx.clearRect(-can.width/2,-can.height/2,can.width,can.height); | |
for (var i = 0; i < 6; i++) { | |
drawLine(0); | |
ctx.rotate(Math.PI * 2 / 6); | |
} | |
requestAnimationFrame(go); | |
} | |
go() | |
function drawLine(level) { | |
if(level>3) return; | |
ctx.strokeStyle = '#000'; | |
ctx.lineWidth = 3; | |
ctx.beginPath(); | |
ctx.moveTo(0, 0); | |
ctx.lineTo(200, 0); | |
ctx.stroke(); | |
for (var i = 0; i < 2; i++) { | |
ctx.save(); | |
ctx.translate(200 * i / (branches + 1), 0); | |
ctx.scale(0.5, 0.5); | |
ctx.save(); | |
ctx.rotate(angle); | |
drawLine(level + 1); | |
ctx.restore(); | |
ctx.save(); | |
ctx.rotate(-angle); | |
drawLine(level + 1); | |
ctx.restore(); | |
ctx.restore(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment