2019-01-20 16:45:57 +00:00
|
|
|
%import c64lib
|
2018-10-21 21:03:15 +00:00
|
|
|
%import c64utils
|
2019-01-05 15:09:05 +00:00
|
|
|
%import c64flt
|
2019-02-12 22:24:47 +00:00
|
|
|
%zeropage basicsafe
|
|
|
|
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2019-07-29 21:11:13 +00:00
|
|
|
main {
|
2019-01-08 00:27:25 +00:00
|
|
|
const uword width = 30
|
|
|
|
const uword height = 20
|
|
|
|
const ubyte max_iter = 16
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2018-09-30 16:49:58 +00:00
|
|
|
sub start() {
|
2019-03-13 21:45:12 +00:00
|
|
|
c64scr.print("calculating mandelbrot fractal...")
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2019-01-08 00:27:25 +00:00
|
|
|
c64.TIME_HI=0
|
|
|
|
c64.TIME_MID=0
|
|
|
|
c64.TIME_LO=0
|
2018-09-23 00:42:42 +00:00
|
|
|
|
2019-01-08 00:27:25 +00:00
|
|
|
for ubyte pixely in 0 to height-1 {
|
|
|
|
float yy = (pixely as float)/0.4/height - 1.0
|
|
|
|
|
|
|
|
for ubyte pixelx in 0 to width-1 {
|
|
|
|
float xx = (pixelx as float)/0.3/width - 2.2
|
2018-10-06 22:21:13 +00:00
|
|
|
|
|
|
|
float xsquared = 0.0
|
|
|
|
float ysquared = 0.0
|
|
|
|
float x = 0.0
|
|
|
|
float y = 0.0
|
2018-10-10 07:21:20 +00:00
|
|
|
ubyte iter = 0
|
2018-10-06 22:21:13 +00:00
|
|
|
|
2019-01-08 00:27:25 +00:00
|
|
|
while (iter<max_iter and xsquared+ysquared<4.0) {
|
2018-10-05 15:44:29 +00:00
|
|
|
y = x*y*2.0 + yy
|
2018-09-26 23:35:35 +00:00
|
|
|
x = xsquared - ysquared + xx
|
|
|
|
xsquared = x*x
|
|
|
|
ysquared = y*y
|
2018-09-23 00:42:42 +00:00
|
|
|
iter++
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
2019-01-08 00:27:25 +00:00
|
|
|
c64scr.setcc(pixelx+4, pixely+1, 160, max_iter-iter)
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-15 20:35:15 +00:00
|
|
|
|
2019-07-02 20:27:31 +00:00
|
|
|
float duration = ((c64.TIME_LO as float)
|
2019-01-26 16:32:26 +00:00
|
|
|
+ 256.0*(c64.TIME_MID as float)
|
2019-07-02 20:27:31 +00:00
|
|
|
+ 65536.0*(c64.TIME_HI as float))/60.0
|
2019-03-21 21:36:46 +00:00
|
|
|
c64scr.plot(0, 21)
|
2019-01-08 00:27:25 +00:00
|
|
|
c64scr.print("finished in ")
|
|
|
|
c64flt.print_f(duration)
|
|
|
|
c64scr.print(" seconds!\n")
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|