Rebol3 Code Examplex
Mandelbrot set
Render points of the Mandelbrot fractal.
Rebol [
title: "Rosetta code: Mandelbrot set"
file: %Mandelbrot_set.r3
url: https://rosettacode.org/wiki/Mandelbrot_set
needs: 3.0.0
]
ascii-mandelbrot: function [
"Integer ASCII Mandelbrot generator"
][
;; Define edges and steps
leftEdge: -420
rightEdge: 300
topEdge: 300
bottomEdge: -300
xStep: 7
yStep: 15
maxIter: 200
;; Prebuild character map for iterations 0–10
chars: "0123456789@"
;; Loop over rows (y0 from topEdge down to bottomEdge)
for y0 topEdge bottomEdge negate yStep [
;; Loop over columns (x0 from leftEdge up to rightEdge)
for x0 leftEdge rightEdge xStep [
;; Initialize iteration state
x: y: i: 0 theChar: SP
;; Iterate until divergence or maxIter
while [i < maxIter] [
;; Compute scaled squares
x_x: to integer! (x * x / 200)
y_y: to integer! (y * y / 200)
;; Check escape condition
either x_x + y_y > 800 [
;; Choose character based on iteration count
theChar: pick chars either i > 9 [10] [i]
;; Break by setting i to maxIter
i: maxIter
][
;; Continue Mandelbrot iteration
y: to integer! ((x * y) / 100) + y0
x: x_x - y_y + x0
i: i + 1
]
]
;; Print character for this point
prin theChar
]
;; Newline at end of row
print ""
]
]
;; evaluate....
ascii-mandelbrotOutput:
0000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111100000
0000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111100
0000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111
0000000000000000111111111111111111122222222222222222222222111111111111111111111111111111111111111111111
0000000000000001111111111111222222222222222222222222222222222222111111111111111111111111111111111111111
0000000000000111111111122222222222222222222222223333346544433332222221111111111111111111111111111111111
0000000000001111111122222222222222222222222333333334455995554333333222222111111111111111111111111111111
0000000000011111122222222222222222222222333333333444456799996543333332222222111111111111111111111111111
000000000111111222222222222222222222233333333334444567899 987644433333322222221111111111111111111111111
0000000011112222222222222222222222233333333334445557999 99965444433333222222211111111111111111111111
000000011112222222222222222222223333333334445555666799 9876555444433322222222111111111111111111111
0000000112222222222222222222223333333444459999988999999 99999976666894332222222211111111111111111111
000000112222222222222222222333334444444556899 99 99999997433222222222111111111111111111
0000011222222222222222233334444444445555678999 975443322222222211111111111111111
000001222222222222233335555544444555566799 9 9976544332222222221111111111111111
000012222222233333344457987667897666677999 999954333222222221111111111111111
000022223333333344444557899 9999999988999 99654333222222222111111111111111
000022333333334444445667899 9999 9744333222222222111111111111111
00013333333344444557988999 9 99544333322222222211111111111111
0002344444555556667899 9 75544333322222222211111111111111
000 99765444333322222222211111111111111
0002344444555556667899 9 75544333322222222211111111111111
00013333333344444557988999 9 99544333322222222211111111111111
000022333333334444445667899 9999 9744333222222222111111111111111
000022223333333344444557899 9999999988999 99654333222222222111111111111111
000012222222233333344457987667897666677999 999954333222222221111111111111111
000001222222222222233335555544444555566799 9 9976544332222222221111111111111111
0000011222222222222222233334444444445555678999 975443322222222211111111111111111
000000112222222222222222222333334444444556899 99 99999997433222222222111111111111111111
0000000112222222222222222222223333333444459999988999999 99999976666894332222222211111111111111111111
000000011112222222222222222222223333333334445555666799 9876555444433322222222111111111111111111111
0000000011112222222222222222222222233333333334445557999 99965444433333222222211111111111111111111111
000000000111111222222222222222222222233333333334444567899 987644433333322222221111111111111111111111111
0000000000011111122222222222222222222222333333333444456799996543333332222222111111111111111111111111111
0000000000001111111122222222222222222222222333333334455995554333333222222111111111111111111111111111111
0000000000000111111111122222222222222222222222223333346544433332222221111111111111111111111111111111111
0000000000000001111111111111222222222222222222222222222222222222111111111111111111111111111111111111111
0000000000000000111111111111111111122222222222222222222222111111111111111111111111111111111111111111111
0000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111
0000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111100
0000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111100000