Jump to content

Module:Wnt/Templates/Mandelbrot

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Wnt/Templates/Mandelbrot/doc

local p = {}
function field (xmin, xmax, xres, ymin, ymax, yres)
   local y, x
   local output=""
   for y = ymin, ymax, yres do
      for x = xmin, xmax, xres do
          local tx = 0
          local ty = 0
          local i=1024
          while ((tx*tx + ty*ty) < 4) do
             tx = tx*tx - ty*ty + x
             ty = 2 * tx * ty + y
             i=i-1
             if i==0 then tx=100 end
          end
          if i==0 then output=output .. "█" else output=output .. "⁣ " end
       end
       output=output .. "<br />"
    end
    return output
end

function p.main(frame)
   return field(frame.args.xmin or -2, frame.args.xmax or 2, frame.args.xres or 0.1, frame.args.ymin or -2, frame.args.ymax or 2, frame.args.yres or 0.1)
end

return p