2018-12-18 14:12:56 +00:00
|
|
|
%import c64utils
|
|
|
|
%option enable_floats
|
|
|
|
|
|
|
|
~ main {
|
|
|
|
const uword width = 30
|
|
|
|
const uword height = 20
|
2018-12-19 01:51:22 +00:00
|
|
|
const ubyte max_iter = 16
|
2018-12-18 14:12:56 +00:00
|
|
|
|
|
|
|
sub start() {
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("calculating mandelbrot fractal...\n")
|
2018-12-18 14:12:56 +00:00
|
|
|
|
2018-12-19 01:51:22 +00:00
|
|
|
c64.TIME_HI=0
|
|
|
|
c64.TIME_MID=0
|
|
|
|
c64.TIME_LO=0
|
|
|
|
|
2018-12-18 14:12:56 +00:00
|
|
|
for ubyte pixely in 0 to height-1 {
|
2018-12-24 23:33:04 +00:00
|
|
|
float yy = (pixely as float)/0.4/height-1.0
|
2018-12-18 14:12:56 +00:00
|
|
|
|
|
|
|
for ubyte pixelx in 0 to width-1 {
|
2018-12-24 23:33:04 +00:00
|
|
|
float xx = (pixelx as float)/0.3/width-2.0
|
2018-12-18 14:12:56 +00:00
|
|
|
|
|
|
|
float xsquared = 0.0
|
|
|
|
float ysquared = 0.0
|
|
|
|
float x = 0.0
|
|
|
|
float y = 0.0
|
|
|
|
ubyte iter = 0
|
|
|
|
|
2018-12-19 01:51:22 +00:00
|
|
|
while (iter<max_iter and xsquared+ysquared<4.0) {
|
2018-12-18 14:12:56 +00:00
|
|
|
y = x*y*2.0 + yy
|
|
|
|
x = xsquared - ysquared + xx
|
|
|
|
xsquared = x*x
|
|
|
|
ysquared = y*y
|
|
|
|
iter++
|
|
|
|
}
|
|
|
|
|
2018-12-19 01:51:22 +00:00
|
|
|
c64.CHROUT(32+max_iter-iter)
|
2018-12-18 14:12:56 +00:00
|
|
|
}
|
|
|
|
c64.CHROUT('\n')
|
|
|
|
}
|
2018-12-24 23:33:04 +00:00
|
|
|
float duration = floor(((c64.TIME_LO as float) + 256.0*(c64.TIME_MID as float) + 65536.0*(c64.TIME_HI as float))/60.0)
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("finished in ")
|
|
|
|
c64flt.print_f(duration)
|
|
|
|
c64scr.print(" seconds!\n")
|
2018-12-18 14:12:56 +00:00
|
|
|
}
|
|
|
|
}
|