mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
optimized mandelbrot example
This commit is contained in:
parent
68037e4425
commit
3a0c1c5ada
@ -1,38 +0,0 @@
|
||||
%zeropage full
|
||||
%address 33
|
||||
%option enable_floats
|
||||
%option enable_floats
|
||||
|
||||
~ extra {
|
||||
; this is imported
|
||||
|
||||
X = 42
|
||||
return 44
|
||||
}
|
||||
|
||||
~ extra2 {
|
||||
; this is imported
|
||||
|
||||
X = 42
|
||||
return 44
|
||||
|
||||
label_in_extra2:
|
||||
X = 33
|
||||
return
|
||||
|
||||
sub sub_in_extra2() -> () {
|
||||
return
|
||||
}
|
||||
sub another_sub_in_extra2() -> () {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~ main2 {
|
||||
; this is imported
|
||||
|
||||
X = 42
|
||||
return 44
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
%zeropage full
|
||||
%address 33
|
||||
|
||||
~ extra3 {
|
||||
; this is imported
|
||||
|
||||
X = 42
|
||||
return 44
|
||||
}
|
||||
|
||||
~ extra233 {
|
||||
; this is imported
|
||||
|
||||
const byte snerp=33
|
||||
const byte snerp2 = snerp+22
|
||||
|
||||
X = 42+snerp
|
||||
;return 44+snerp
|
||||
return
|
||||
|
||||
sub foo234234() -> () {
|
||||
A=99+snerp
|
||||
;return A+snerp2
|
||||
return
|
||||
}
|
||||
|
||||
sub thingy()->(X) {
|
||||
;return 99
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~ mainzzz {
|
||||
; this is imported
|
||||
|
||||
X = 42
|
||||
;return 44
|
||||
return
|
||||
}
|
||||
|
@ -4,48 +4,49 @@
|
||||
|
||||
sub start() -> () {
|
||||
|
||||
const word width = 320
|
||||
const word height = 256
|
||||
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
|
||||
float x2
|
||||
float xsq
|
||||
float ysq
|
||||
byte iter
|
||||
word plotx
|
||||
byte ploty
|
||||
|
||||
_vm_write_str("Calculating Mandelbrot fractal, have patience...\n")
|
||||
_vm_gfx_clearscr(11)
|
||||
_vm_gfx_text(5, 5, 7, "Calculating Mandelbrot Fractal...")
|
||||
|
||||
for pixely in 0 to height-1 {
|
||||
for pixelx in 0 to width-1 {
|
||||
xx = pixelx/width/3+0.2
|
||||
yy = pixely/height/3.6+0.4
|
||||
for pixely in yoffset to yoffset+height-1 {
|
||||
yy = (pixely-yoffset)/height/3.6+0.4
|
||||
|
||||
for pixelx in xoffset to xoffset+width-1 {
|
||||
xx = (pixelx-xoffset)/width/3+0.2
|
||||
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
|
||||
for iter in 0 to 31 {
|
||||
if (x*x + y*y > 4) break
|
||||
x2 = x*x - y*y + xx
|
||||
xsq = 0
|
||||
ysq = 0
|
||||
iter = 0
|
||||
while (iter<32 and xsq+ysq<4) {
|
||||
y = x*y*2 + yy
|
||||
x = x2
|
||||
x = xsq - ysq + xx
|
||||
xsq = x*x
|
||||
ysq = y*y
|
||||
iter++
|
||||
}
|
||||
|
||||
_vm_gfx_pixel(pixelx, pixely, iter)
|
||||
; plotx = pixelx*2
|
||||
; ploty = pixely*2
|
||||
; _vm_gfx_pixel(plotx, ploty, iter)
|
||||
; _vm_gfx_pixel(plotx+1, ploty, iter)
|
||||
; _vm_gfx_pixel(plotx, ploty+1, iter)
|
||||
; _vm_gfx_pixel(plotx+1, ploty+1, iter)
|
||||
}
|
||||
}
|
||||
|
||||
_vm_gfx_text(5, 5, 7, "Mandelbrot Fractal")
|
||||
_vm_gfx_text(110, 160, 7, "Finished!")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -794,6 +794,7 @@ private class StatementTranslator(private val stackvmProg: StackVmProgram, priva
|
||||
val loopLabel = makeLabel("loop")
|
||||
val breakLabel = makeLabel("break")
|
||||
val continueLabel = makeLabel("continue")
|
||||
stackvmProg.line(stmt.position)
|
||||
breakStmtLabelStack.push(breakLabel)
|
||||
continueStmtLabelStack.push(continueLabel)
|
||||
stackvmProg.instr(Opcode.JUMP, callLabel = continueLabel)
|
||||
@ -827,6 +828,7 @@ private class StatementTranslator(private val stackvmProg: StackVmProgram, priva
|
||||
val loopLabel = makeLabel("loop")
|
||||
val continueLabel = makeLabel("continue")
|
||||
val breakLabel = makeLabel("break")
|
||||
stackvmProg.line(stmt.position)
|
||||
breakStmtLabelStack.push(breakLabel)
|
||||
continueStmtLabelStack.push(continueLabel)
|
||||
stackvmProg.label(loopLabel)
|
||||
|
Loading…
Reference in New Issue
Block a user