From 84f193befd3822a405daa4599ca1eab05ae1af05 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 13 Mar 2026 14:26:28 +0300 Subject: [PATCH] Add mandelbrot example --- examples/mandelbrot.psl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/mandelbrot.psl diff --git a/examples/mandelbrot.psl b/examples/mandelbrot.psl new file mode 100644 index 0000000..a0beafb --- /dev/null +++ b/examples/mandelbrot.psl @@ -0,0 +1,30 @@ +foreign func putchar(c: i32) -> i32 + +func print(c: u8): + putchar(c as i32) + +func mandelbrot(): + let width = 120 + let height = 40 + mut y = 0 + while y < height: + mut x = 0 + while x < width: + let cx = (x as f32 + 0.5) / (width as f32) * 2.5 - 2.0 + let cy = (y as f32 + 0.5) / (height as f32) * 2.0 - 1.0 + mut tx = 0.0 + mut ty = 0.0 + mut i = 0 + while i < 100 && (tx * tx + ty * ty < 4.0): + let newx = tx * tx - ty * ty + cx + ty = 2.0 * tx * ty + cy + tx = newx + i = i + 1 + if i == 100: + print('X') + else: + print(' ') + + x = x + 1 + y = y + 1 + print('\n')