How to program a fractal?

后端 未结 14 994
花落未央
花落未央 2020-12-04 05:34

I do not have any experience with programming fractals. Of course I\'ve seen the famous Mandelbrot images and such.

Can you provide me with simple algorithms for fra

14条回答
  •  佛祖请我去吃肉
    2020-12-04 05:52

    Here is a codepen that I wrote for the Mandelbrot fractal using plain javascript and HTML.

    Hopefully it is easy to understand the code.

    The most complicated part is scale and translate the coordinate systems. Also complicated is making the rainbow palette.

    function mandel(x,y) {
      var a=0; var b=0;
      for (i = 0; i<250; ++i) {
        // Complex z = z^2 + c
        var t = a*a - b*b;
        b = 2*a*b;
        a = t;
        a = a + x;
        b = b + y;
        var m = a*a + b*b;
        if (m > 10)  return i;
      }
      return 250;
    }
    

提交回复
热议问题