RosettaCodeData/Task/Mandelbrot-set/XPL0/mandelbrot-set.xpl0
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

26 lines
1.5 KiB
Text

include c:\cxpl\codes; \intrinsic 'code' declarations
int X, Y, \screen coordinates of current point
Cnt; \iteration counter
real Cx, Cy, \coordinates scaled to +/-2 range
Zx, Zy, \complex accumulator
Temp; \temporary scratch
[SetVid($112); \set 640x480x24 graphics mode
for Y:= 0 to 480-1 do \for all points on the screen...
for X:= 0 to 640-1 do
[Cx:= (float(X)/640.0 - 0.5) * 4.0; \range: -2.0 to +2.0
Cy:= (float(Y-240)/240.0) * 1.5; \range: -1.5 to +1.5
Cnt:= 0; Zx:= 0.0; Zy:= 0.0; \initialize
loop [if Zx*Zx + Zy*Zy > 2.0 then \Z heads toward infinity
[Point(X, Y, Cnt<<21+Cnt<<10+Cnt<<3); \set color of pixel to
quit; \ rate it approached infinity
]; \move on to next point
Temp:= Zx*Zy;
Zx:= Zx*Zx - Zy*Zy + Cx; \calculate next iteration of Z
Zy:= 2.0*Temp + Cy;
Cnt:= Cnt+1; \count number of iterations
if Cnt >= 1000 then quit; \assume point is in Mandelbrot
]; \ set and leave it colored black
];
X:= ChIn(1); \wait for keystroke
SetVid($03); \restore normal text display
]