2014-09-16 23:12:03 +08:00
|
|
|
import sys
|
|
|
|
|
2014-09-30 17:38:02 +08:00
|
|
|
from artiq import *
|
2014-09-16 23:12:03 +08:00
|
|
|
|
2014-09-30 17:38:02 +08:00
|
|
|
|
2015-01-12 18:51:23 +08:00
|
|
|
class Mandelbrot(AutoDB):
|
2015-02-21 05:01:34 +08:00
|
|
|
__artiq_unit__ = "Mandelbrot set demo"
|
|
|
|
|
2015-03-08 18:37:53 +08:00
|
|
|
class DBKeys:
|
|
|
|
core = Device()
|
|
|
|
|
2014-09-16 23:12:03 +08:00
|
|
|
def col(self, i):
|
|
|
|
sys.stdout.write(" .,-:;i+hHM$*#@ "[i])
|
|
|
|
|
|
|
|
def row(self):
|
|
|
|
print("")
|
|
|
|
|
|
|
|
# based on: http://warp.povusers.org/MandScripts/python.html
|
|
|
|
@kernel
|
|
|
|
def run(self):
|
|
|
|
minX = -2.0
|
|
|
|
maxX = 1.0
|
|
|
|
width = 78
|
|
|
|
height = 36
|
|
|
|
aspectRatio = 2
|
|
|
|
|
|
|
|
yScale = (maxX-minX)*(height/width)*aspectRatio
|
|
|
|
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
c_r = minX+x*(maxX-minX)/width
|
|
|
|
c_i = y*yScale/height-yScale/2
|
|
|
|
z_r = c_r
|
|
|
|
z_i = c_i
|
|
|
|
for i in range(16):
|
|
|
|
if z_r*z_r + z_i*z_i > 4:
|
|
|
|
break
|
|
|
|
new_z_r = (z_r*z_r)-(z_i*z_i) + c_r
|
|
|
|
z_i = 2*z_r*z_i + c_i
|
|
|
|
z_r = new_z_r
|
|
|
|
self.col(i)
|
|
|
|
self.row()
|