Mandelbrot set

You are encouraged to solve this task according to the task description, using any language you may know.


Task

Generate and draw the Mandelbrot set.



Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .




 
Module Mandelbrot(x=0&,y=0&,z=1&) {
      If z<1  then z=1
      If z>16 then z=16
      Const iXmax=32*z
      Const iYmax=26*z
      Def single Cx, Cy, CxMin=-2.05, CxMax=0.85, CyMin=-1.2,  CyMax=1.2
      Const PixelWidth=(CxMax-CxMin)/iXmax, iXm=(iXmax-1)*PixelWidth
      Const PixelHeight=(CyMax-CyMin)/iYmax,Ph2=PixelHeight/2
      Const Iteration=25
      Const EscRadious=2.5, ER2=EscRadious**2
      Def single preview
      preview=iXmax*twipsX*(z/16)
      Def long yp, xp, dx, dy, dx1, dy1
      Let dx=twipsx*(16/z), dx1=dx-1
      Let dy=twipsy*(16/z), dy1=dy-1
      yp=y
      For iY=0 to (iYmax-1)*PixelHeight step PixelHeight {
            Cy=CyMin+iY
            xp=x
            if abs(Cy)<Ph2 Then Cy=0
            For iX=0 to iXm Step PixelWidth {
                  Let  Cx=CxMin+iX,Zx=0,Zy=0,Zx2=Zx**2,Zy2=Zy**2
                  For It=Iteration to 1 {Let Zy=2*Zx*Zy+Cy,Zx=Zx2-Zy2+Cx,Zx2=Zx**2,Zy2=Zy**2 :if Zx2+Zy2>ER2 Then exit
                  }
                  if it>13 then {it-=13} else.if it=0 then SetPixel(xp,yp,0): xp+=dx : continue
                  it*=10:SetPixel(xp,yp,color(it, it,255)) :xp+=dx
            } : yp+=dy
      }
      Sub SetPixel()
            move number, number: fill  dx1, dy1, number
      End Sub
}
Cls 1,0
sz=(1,2,4,8,16)
i=each(sz)
While i {
      Mandelbrot 250*twipsx,100*twipsy, array(i)
}
 
 