Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
crsn/examples/mandelbrot/mandelbrot-ascii.csn

87 lines
1.7 KiB

(
(def W 128)
(def H 48)
(def MAXITER 50)
(sym asciigr r10)
(mkbf asciigr (
'.' ',' ':' '+' '=' '%' '@' '#'
'$' '&' '*' '|' '-' ':' '.' ' '
))
(sym x r7)
(sym y r8)
(:row)
(:col)
(call pixel x y)
(sub r0 MAXITER 1)
(rcmp res0 1 r0
(eq?
(mod r0 res0 16)
(bfrd @cout @asciigr r0)
)
(else?
(ld @cout ' ')
)
)
(sc-wr x y r0)
(inc x)
(cmp x W)
(j.ne :col)
(ld x 0)
(inc y)
(ld @cout '\n')
(cmp y H)
(j.ne :row)
(halt)
(proc pixel xi yi
(sym x0 r7)
(sym y0 r8)
(itf x0 xi)
(itf y0 yi)
; Scale to the interesting range
(itf r0 W)
(itf r1 H)
(fdiv x0 r0)
(fmul x0 3.5)
(fsub x0 2.5)
(fdiv y0 r1)
(fmul y0 2.4)
(fsub y0 1.2)
(sym x r5)
(sym y r6)
(ld x 0.0)
(ld y 0.0)
(sym iter r4)
(:iter)
(cmp iter MAXITER)
(j.eq :end)
(fmul r0 x x)
(fmul r1 y y)
(fadd r2 r1)
(fcmp r2 4.0)
(j.gt :end)
(fsub r2 r0 r1)
(fadd r2 x0)
(fmul r0 x y)
(fmul r0 2.0)
(fadd r0 y0)
(ld y r0)
(ld x r2)
(inc iter)
(j :iter)
(:end)
(ret iter)
)
)