Live data from Hacker News

Show HN: JavaScript Fractal implementation in a single tweet

twitter.com

1–6 of 6 posts

Re: Show HN: JavaScript Fractal implementation in a single tweet

#2
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 (([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:

F()

Demo here: https://runkit.com/asyncanup/5cd629840a18bf001b4860e9

Re: Show HN: JavaScript Fractal implementation in a single tweet

#3

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 (([x,y],i)=>(c.moveTo(x,y),c.lineTo(X=x+3 C[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: F() Demo here: h…

I think you could shave off 8 characters by doing

  0|Math.random()*3
instead of

  parseInt(Math.random()*3)

Re: Show HN: JavaScript Fractal implementation in a single tweet

#4
post #3

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 (([x,y],i)=>(c.moveTo(x,y),c.lineTo(X=x+3 C[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: F() Demo here: h…

I think you could shave off 8 characters by doing 0|Math.random()*3 instead of parseInt(Math.random()*3)

[deleted]

Re: Show HN: JavaScript Fractal implementation in a single tweet

#5

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 (([x,y],i)=>(c.moveTo(x,y),c.lineTo(X=x+3 C[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: F() Demo here: h…

Further, you could shave off a couple of bytes by inserting

  
before the canvas element, instead of having

  F()
after the canvas element

Re: Show HN: JavaScript Fractal implementation in a single tweet

#6
Here is a collection of fractals in 140 characters (or less!) of JavaScript: https://www.dwitter.net/h/fractal It includes Mandelbrot, Fern, Iterated Function System (IFS), Cantor Set, Dragon Curves, fractal animations and other recursive functions and iterated geometric transformations. Dwitter is a great place to find clever code tricks and very short algorithm implementations.