# Category: Complex Analysis
# Name: Mandelbrot set
#
# Draw the Mandelbrot set
#

iterations = 30;

LinePlotWindow = [-2,2,-2,2];

LinePlotDrawLegends = false;
PlotWindowPresent(); # Make sure the window is raised

points = null;

k=1;

function DrawThePlot () = (
  PlotCanvasFreeze ();
  LinePlotClear ();
  LinePlotDrawPoints (points, "color", "green", "thickness", 3);
  PlotCanvasThaw ();
);

for x = -2.0 to 2.0 by 0.02 do (
  for y = -2.0 to 2.0 by 0.02 do (
    c = z = x+1i*y;
    for m=0 to iterations do (
      z = z^2+c;
      if |z| >= 2.0 then break
    );
    if m == iterations then
      points = [points;c];
    
    increment k;
    # every 500's point display intermediate picture
    if k % 500 == 0 then
      DrawThePlot()
  )
);

DrawThePlot();
