3 ms·
Hi, author here. Here's the code: F=()=>{ c=v.getContext('2d') c.lineWidth=.03 C=[1,-.5,-.5] S=[0,.87,-.87] P=[[X=300,Y=300],[X,Y],[X,Y]] R=()=>{d=parseInt(Ma
by asyncanup 7y ago
Hi, author here.
Here's the code:
F=()=>{
c=v.getContext('2d')
c.lineWidth=.03
C=[1,-.5,-.5]
S=[0,.87,-.87]
P=[[X=300,Y=300],[X,Y],[X,Y]]
R=()=>{d=parseInt(Math.random()3)
P=http://P.map http://P.map (([x,y],i)=>(c.moveTo(x,y),c.lineTo(X=x+3C[I=(d+i)%3],Y=y+3*S[I]),[X,Y]))
c.stroke()
setTimeout(R,17)
}
R()}
Assumes no existing dependencies or dwitter-like shortcuts available.
Needs this HTML to be on the page:
<canvas width=400 height=400 id="v"></canvas><script>F()</script>
Demo here: https://runkit.com/asyncanup/5cd629840a18bf001b4860e9 https://runkit.com/asyncanup/5cd629840a18bf001b4860e9
- iverjo 7y agoI think you could shave off 8 characters by doing 0|Math.random()*3 instead of parseInt(Math.random()*3)
- deleted 7y ago[deleted]
- iverjo 7y agoFurther, you could shave off a couple of bytes by inserting <body onload=F()> before the canvas element, instead of having <script>F()</script> after the canvas element