32 lines
605 B
PSL
32 lines
605 B
PSL
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')
|
|
|
|
mandelbrot()
|