sw=640
sh=512
open window sw,sh
mr = -2.0
xr = 1.0
mi = -1.2
xi = mi+(xr-mr)*sh/sw
rfc = (xr-mr)/(sw-1)
ifc = (xi-mi)/(sh-1)
mxi = 30
shade=255/mxi
gosub drawit
exit

label drawit
 clear window
 for y=0 to sh-1
  ci=xi-y*ifc
  for x=0 to sw-1
   cr=mr+x*rfc
   zr=cr
   zi=ci
   isinside=1
   bri=0
   for n=0 to mxi-1
    bri=bri+1
    zr2=zr*zr
    zi2=zi*zi
    if (zr2+zi2)>4 then
     isinside=0
     n=mxi-1
    fi
    zi=2*zr*zi+ci
    zr=zr2-zi2+cr
   next n
   if isinside=1 then
    setrgb 1,0,0,0
   else
    col=bri*shade
    if col>128 then
     setrgb 1,col,col-128,col-128
    else
     setrgb 1,bri*shade,0,0
    fi
   fi
   fill rectangle x,y to x+1,y+1
  next x
 next y
return
