Funny, I was just playing with fractals on canvas the other day. Specifically the Barnsley Fern. I think it's a very interesting way to build and understand fractal structures. Also, it's great to see them build up pixel per pixel.
Here's my quick & dirty implementation.
// mathjs (http://mathjs.org) imported in the HTMLconsttransformations=[{p:0.03,m:[[0,0],[0,0.16]],n:[0,0]},{p:0.85,m:[[0.85,0.04],[-0.04,0.85]],n:[0,1.60]},{p:0.06,m:[[0.20,-0.26],[0.23,0.22]],n:[0,1.60]},{p:0.06,m:[[-0.15,0.28],[0.26,0.24]],n:[0,0.44]}]functiontransform(pos){r=math.random()for(toftransformations){if(r<t.p){returnmath.add(math.multiply(t.m,pos),t['n'])}else{r-=t.p}}}document.addEventListener('DOMContentLoaded',()=>{// 800x600 canvas element created in the HTMLconstcontext=document.getElementById('canvas').getContext('2d')varpos=[0,0]window.setInterval(()=>{context.save()context.transform(1,0,0,-1,400,600)// flip the canvas vertically, and set origin to bottom middlecontext.fillRect(pos[0]*50,pos[1]*50,1,1)// scale pos by 50pos=transform(pos)context.restore()},.01)})
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Funny, I was just playing with fractals on canvas the other day. Specifically the Barnsley Fern. I think it's a very interesting way to build and understand fractal structures. Also, it's great to see them build up pixel per pixel.
Here's my quick & dirty implementation.