prog8/examples/mandelbrot.p8

52 lines
1.3 KiB
Plaintext
Raw Normal View History

%import textio
%import floats
2020-11-22 17:17:43 +00:00
%import test_stack
2019-02-12 22:24:47 +00:00
%zeropage basicsafe
; Note: this program can be compiled for multiple target systems.
2019-07-29 21:11:13 +00:00
main {
const uword width = 30
const uword height = 20
const ubyte max_iter = 16
sub start() {
2020-08-27 16:10:22 +00:00
txt.print("calculating mandelbrot fractal...")
cbm.SETTIM(0, 0, 0)
2018-09-23 00:42:42 +00:00
ubyte pixelx
ubyte pixely
for pixely in 0 to height-1 {
float yy = (pixely as float)/0.4/height - 1.0
for pixelx in 0 to width-1 {
float xx = (pixelx as float)/0.3/width - 2.2
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
2020-06-17 23:35:24 +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++
}
2020-08-27 16:10:22 +00:00
txt.setcc(pixelx+4, pixely+1, 160, max_iter-iter)
}
}
float duration = (cbm.RDTIM16() as float) / 60
2020-08-27 16:10:22 +00:00
txt.plot(0, 21)
txt.print("finished in ")
floats.print(duration)
2020-08-27 16:10:22 +00:00
txt.print(" seconds!\n")
2020-11-22 17:17:43 +00:00
; test_stack.test()
}
}