Last active
April 22, 2017 09:26
-
-
Save butackle/ab2b124d07dc3933582dda70750812e1 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
[...Array(4)].reduce((l, c, i, a) => i + 1 === a.length ? l.replace(/\$\{(L|R)\}/g, '') : l.replace(/\}/g, '#}').replace(/\$\{L#\}/g, 'L${R}FR${L}F${L}RF${R}L').replace(/\$\{R#\}/g, 'R${L}FL${R}F${R}LF${L}R'),'L${R}FR${L}F${L}RF${R}L').split("F").slice(0, -1).reduce(({ x, y, ctx, dir }, LR, i) => Object.assign({},{ d : dir = LR.split("").map((lr) => lr === "L" ? 1 : -1).reduce((dir, lr) => (dir + 90 * lr) >= 360 ? 0 : (dir + 90 * lr) < 0 ? 360 + (dir + 90 * lr) : (dir + 90 * lr) , dir), dir }, { xx: dir === 90 ? x += 10 : dir === 270 ? x -= 10 : x, yy: dir === 0 ? y += 10 : dir === 180 ? y -= 10 : y, },{ l: setTimeout( () => { ctx.lineTo(x, y),ctx.stroke() }, i * 10) }, { x, y, ctx, dir }), { x: 10, y: 10, dir: 0, c:[ctx = canvas.getContext('2d'), ctx.beginPath(), ctx.moveTo(10, 10)] , ctx}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment