2020-09-20 23:49:36 +02:00
|
|
|
%import textio
|
|
|
|
%import floats
|
2020-11-22 18:17:43 +01:00
|
|
|
%import test_stack
|
2019-02-12 23:24:47 +01:00
|
|
|
%zeropage basicsafe
|
|
|
|
|
2020-09-22 01:34:05 +02:00
|
|
|
; Note: this program is compatible with C64 and CX16.
|
2020-09-20 23:49:36 +02:00
|
|
|
|
2019-07-29 23:11:13 +02:00
|
|
|
main {
|
2019-01-08 01:27:25 +01:00
|
|
|
const uword width = 30
|
|
|
|
const uword height = 20
|
|
|
|
const ubyte max_iter = 16
|
2018-09-18 23:14:32 +02:00
|
|
|
|
2018-09-30 18:49:58 +02:00
|
|
|
sub start() {
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("calculating mandelbrot fractal...")
|
2020-09-26 19:14:06 +02:00
|
|
|
c64.SETTIM(0, 0, 0)
|
2018-09-23 02:42:42 +02:00
|
|
|
|
2019-08-18 03:16:23 +02:00
|
|
|
ubyte pixelx
|
|
|
|
ubyte pixely
|
|
|
|
|
|
|
|
for pixely in 0 to height-1 {
|
2019-01-08 01:27:25 +01:00
|
|
|
float yy = (pixely as float)/0.4/height - 1.0
|
|
|
|
|
2019-08-18 03:16:23 +02:00
|
|
|
for pixelx in 0 to width-1 {
|
2019-01-08 01:27:25 +01:00
|
|
|
float xx = (pixelx as float)/0.3/width - 2.2
|
2018-10-07 00:21:13 +02:00
|
|
|
|
|
|
|
float xsquared = 0.0
|
|
|
|
float ysquared = 0.0
|
|
|
|
float x = 0.0
|
|
|
|
float y = 0.0
|
2018-10-10 09:21:20 +02:00
|
|
|
ubyte iter = 0
|
2018-10-07 00:21:13 +02:00
|
|
|
|
2020-06-18 01:35:24 +02:00
|
|
|
while iter<max_iter and xsquared+ysquared<4.0 {
|
2018-10-05 17:44:29 +02:00
|
|
|
y = x*y*2.0 + yy
|
2018-09-27 01:35:35 +02:00
|
|
|
x = xsquared - ysquared + xx
|
|
|
|
xsquared = x*x
|
|
|
|
ysquared = y*y
|
2018-09-23 02:42:42 +02:00
|
|
|
iter++
|
2018-09-18 23:14:32 +02:00
|
|
|
}
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.setcc(pixelx+4, pixely+1, 160, max_iter-iter)
|
2018-09-18 23:14:32 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-15 21:35:15 +01:00
|
|
|
|
2021-01-02 20:59:48 +01:00
|
|
|
float duration = (c64.RDTIM16() as float) / 60
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.plot(0, 21)
|
|
|
|
txt.print("finished in ")
|
2020-09-20 23:49:36 +02:00
|
|
|
floats.print_f(duration)
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print(" seconds!\n")
|
2020-11-22 18:17:43 +01:00
|
|
|
|
|
|
|
; test_stack.test()
|
2018-09-18 23:14:32 +02:00
|
|
|
}
|
|
|
|
}
|