Skip to content

Instantly share code, notes, and snippets.

@butackle
Last active April 22, 2017 09:26
Show Gist options
  • Save butackle/ab2b124d07dc3933582dda70750812e1 to your computer and use it in GitHub Desktop.
Save butackle/ab2b124d07dc3933582dda70750812e1 to your computer and use it in GitHub Desktop.
[...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