prog8/compiler/examples/mandelbrot.p8

53 lines
1.3 KiB
Plaintext
Raw Normal View History

%option enable_floats
~ main {
sub start() -> () {
2018-09-23 00:42:42 +00:00
const word width = 320 // 2
const word height = 256 // 2
const word xoffset = 40
const word yoffset = 20
word pixelx
byte pixely
float xx
float yy
float x
float y
2018-09-23 00:42:42 +00:00
float xsq
float ysq
byte iter
word plotx
byte ploty
_vm_gfx_clearscr(11)
2018-09-23 00:42:42 +00:00
_vm_gfx_text(5, 5, 7, "Calculating Mandelbrot Fractal...")
2018-09-23 00:42:42 +00:00
for pixely in yoffset to yoffset+height-1 {
yy = flt((pixely-yoffset))/height/3.6+0.4 ; @todo why is /height/3.6 not const-folded???
2018-09-23 00:42:42 +00:00
for pixelx in xoffset to xoffset+width-1 {
xx = flt((pixelx-xoffset))/width/3+0.2 ; @todo why is /width/3 not const-folded???
x = 0.0
y = 0.0
2018-09-23 00:42:42 +00:00
xsq = 0
ysq = 0
iter = 0
while (iter<32 and xsq+ysq<4) {
y = x*y*2 + yy
2018-09-23 00:42:42 +00:00
x = xsq - ysq + xx
xsq = x*x
ysq = y*y
iter++
}
_vm_gfx_pixel(pixelx, pixely, iter)
}
}
2018-09-23 00:42:42 +00:00
_vm_gfx_text(110, 160, 7, "Finished!")
}
}