Add mandelbrot example

This commit is contained in:
Nikita Lisitsa 2026-03-13 14:26:28 +03:00
parent 89b6b09be5
commit 84f193befd

30
examples/mandelbrot.psl Normal file
View file

@ -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')