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-lowres.csn

93 lines
1.9 KiB

(
(sc-init 1024 768)
(sc-opt SCREEN_AUTOBLIT 0)
(sc-opt SCREEN_UPSCALE 8)
(def W 128)
(def H 96)
(def MAXITER 50)
(sym gradient r9)
(sym asciigr r10)
(mkbf gradient (
0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1
0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403))
(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 r0 @gradient r0)
)
(else? (ld r0 0))
)
(sc-wr x y r0)
(inc x)
(cmp x W)
(j.ne :col)
(ld x 0)
(inc y)
(sc-blit) ; Render after every row
(cmp y H)
(j.ne :row)
;(sc-blit)
(:slp)
(sc-poll)
(mslp 10)
(j :slp)
(proc pixel xi yi
(sym x0 r7)
(sym y0 r8)
(itf x0 xi)
(itf y0 yi)
; Scale to the interesting range x -2.5..1 and y -1..1
(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)
)
)