apfl/examples/mandelbrot.apfl
Laria Carolin Chabowski 367961e711 GC: Run it automatically
Finally running it automatically :). Method for when to run it was copied
from Crafting Interpreters by Robert Nystrom. Should have bought that book
earlier :D
2026-01-23 21:04:16 +01:00

41 lines
690 B
Text

width := 80
height := 24
maxiter := 100
V+ := { a1::b1 a2::b2 ->
(+ a1 a2)::(+ b1 b2)
}
V* := { a1::b1 a2::b2 ->
(- (* a1 a2) (* b1 b2))::(+ (* a1 b2) (* b1 a2))
}
Vsqared := { x -> V* x x }
Vsqared-abs := { a::b ->
+ (* a a) (* b b)
}
mandel := {
0 _ _ -> true
_ _ _?(has Vsqared-abs > 4) -> false
n c z -> mandel (-- n) c (V+ (Vsqared z) c)
}
mindim := if (< width height) {width} {height}
scale := / 2 mindim
iterdim := { dim body ->
half := / dim 2
for (- half) half { x ->
body (* scale x)
}
}
iterdim height { b ->
line := ""
iterdim width { a ->
line = & line (if (mandel maxiter a::b 0::0) {"#"} {" "})
}
print line
}