nac3/nac3standalone/demo/src/mandelbrot.py

36 lines
826 B
Python
Raw Normal View History

@extern
def output_asciiart(x: int32):
...
2021-09-22 14:30:52 +08:00
def run() -> int32:
minX = -2.0
maxX = 1.0
width = 78
height = 36
2021-09-22 14:30:52 +08:00
aspectRatio = 2.0
yScale = (maxX-minX)*(float(height)/float(width))*aspectRatio
2021-09-22 14:30:52 +08:00
y = 0
2021-09-22 14:30:52 +08:00
while y < height:
x = 0
2021-09-22 14:30:52 +08:00
while x < width:
c_r = minX+float(x)*(maxX-minX)/float(width)
c_i = float(y)*yScale/float(height)-yScale/2.0
2021-09-22 14:30:52 +08:00
z_r = c_r
z_i = c_i
i = 0
while i < 16:
if z_r*z_r + z_i*z_i > 4.0:
break
new_z_r = (z_r*z_r)-(z_i*z_i) + c_r
z_i = 2.0*z_r*z_i + c_i
z_r = new_z_r
i = i + 1
output_asciiart(i)
x = x + 1
2021-09-22 14:30:52 +08:00
output_asciiart(-1)
y = y + 1
2021-09-22 14:30:52 +08:00
return 0