DECLARE STRUCTURE numeric2: 2 OF NUMERIC
DECLARE STRUCTURE numeric3: 3 OF NUMERIC
DECLARE SHARED const2 OF numeric2
DECLARE SHARED const3 OF numeric3

PARACT part1
OPTION ARITHMETIC COMPLEX
DECLARE NUMERIC width,height
DECLARE NUMERIC i,w1,w2
DECLARE EXTERNAL SUB putpixel
ASK PIXEL SIZE (0,0;1,1)width, height
SET POINT STYLE 1
DECLARE NUMERIC left,right,h
LET left=-4
LET right=4
LET h=(right-left)/2
SET WINDOW left,right,-h,h
DRAW axes
LET i=SQR(-1)
LET w1=(-1+SQR(3)*i)/2
LET w2=CONJ(w1)
PUT TO const3 FROM i,w1,w2
PUT TO const2 FROM width,HEIGHT
START part2
CALL Putpixel(0,(width+1)/2,height)
END PARACT

PARACT part2
OPTION ARITHMETIC COMPLEX
DECLARE NUMERIC width,height
DECLARE EXTERNAL SUB PutPixel
GET FROM const2 TO width,height
CALL Putpixel((width+1)/2,width,height)
END PARACT

EXTERNAL SUB putpixel(a,b,pyh)
OPTION ARITHMETIC COMPLEX
DECLARE NUMERIC i,w1,w2
GET FROM const3 TO i,w1,w2
DEF f(z)=z^3-1
DEF g(z)=3*z^2
DECLARE NUMERIC px,py,gz,x0,y0,z,n
FOR px=a TO b
   FOR py=0 TO pyh
      LET x0=PROBLEMX(px)
      LET y0=PROBLEMY(py)
      LET z=COMPLEX(x0,y0)
      FOR n=1 to 100
         LET gz=g(z)
         IF gz<>0 THEN
            LET z=z-f(z)/gz
            IF ABS(z-1)<0.01 THEN
               SEIZE colorplot
                  SET POINT COLOR 3
                  PLOT POINTS : x0, y0
               END SEIZE
               EXIT FOR
            ELSEIF ABS(z-w1)<0.01 THEN
               seize colorplot
                  SET POINT COLOR 2
                  PLOT POINTS : x0, y0
               END SEIZE
               EXIT FOR
            ELSEIF ABS(z-w2)<0.01 THEN
               SEIZE colorplot
                  SET POINT COLOR 4
                  PLOT POINTS : x0, y0
               END SEIZE
               EXIT FOR
            END IF
         END if
      NEXT n
       
   NEXT py
NEXT px
END SUB 

