A2osX/EXAMPLES/MANDELBROT.F.txt
2020-12-17 21:23:54 +01:00

72 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
#!/bin/forth
140 CONSTANT MAXX
70 CONSTANT CENTERX
192 CONSTANT MAXY
92 CONSTANT CENTERY
100 CONSTANT ZOOM
16 CONSTANT MAXITER
0 VARIABLE X
0 VARIABLE Y
0 VARIABLE ZX
0 VARIABLE ZY
0 VARIABLE ZX2
0 VARIABLE ZY2
0 VARIABLE CX
0 VARIABLE CY
0 VARIABLE TMP
0 VARIABLE ITER
\for y in range(0,200)
\ for x in range(0,300)
\ zx = 0
\ zy = 0
\ cx = (x - 200) / ZOOM
\ cy = (y - 100) / ZOOM
\ for iter in range(MAX_ITER)
\ if zx*zx + zy*zy > 4 then break
\ tmp = zx * zx - zy * zy + cx
\ zy = 2 * zx * zy + cy
\ zx = tmp
\ end for
\ if iter then
\ gfx.setPixel x, y, rgb(255-iter*6, 0, iter*6)
\ end if
\ end for
\end for
: CELL
0 ZX !
0 ZY !
0 ITER !
X CENTERX - ZOOM / CX !
Y CENTERY - ZOOM / CY !
MAXITER 0 DO
ZX ZX * ZX2 !
ZY ZY * ZY2 !
ZX2 ZY2 + 4 > IF I ITER ! LEAVE ENDIF
ZX2 ZY2 - CX + TMP !
ZX ZY * 2 * CY + ZY !
TMP ZX !
LOOP
\ Y 4 / X ITER PLOT
Y @ . X @ . ITER @ . CR ;
: MANDELBROT
\ 191 559 0 0 0 RECT
MAXY 0 DO
I Y !
MAXX 0 DO
I X !
CELL
LOOP
LOOP ;
MANDELBROT
MAN
TEXT root/mandelbrot.f