2018-10-21 21:03:15 +00:00
|
|
|
%import c64utils
|
2018-09-18 21:14:32 +00:00
|
|
|
%option enable_floats
|
|
|
|
|
|
|
|
~ main {
|
2018-10-10 07:21:20 +00:00
|
|
|
const uword width = 320 // 2
|
|
|
|
const uword height = 256 // 2
|
|
|
|
const uword xoffset = 40
|
|
|
|
const uword yoffset = 30
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2018-09-30 16:49:58 +00:00
|
|
|
sub start() {
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_gfx_clearscr(11)
|
|
|
|
vm_gfx_text(2, 1, 1, "Calculating Mandelbrot Fractal...")
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2018-10-10 07:21:20 +00:00
|
|
|
for ubyte pixely in yoffset to yoffset+height-1 {
|
2018-12-24 23:33:04 +00:00
|
|
|
float yy = (pixely-yoffset as float)/3.6/height+0.4
|
2018-09-23 00:42:42 +00:00
|
|
|
|
2018-10-10 07:21:20 +00:00
|
|
|
for uword pixelx in xoffset to xoffset+width-1 {
|
2018-12-24 23:33:04 +00:00
|
|
|
float xx = (pixelx-xoffset as float)/3.0/width+0.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
|
|
|
|
2018-10-05 15:44:29 +00:00
|
|
|
while (iter<32 and xsquared+ysquared<4.0) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_gfx_pixel(pixelx, pixely, iter)
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_gfx_text(11, 21, 1, "Finished!")
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|