File indexing completed on 2024-12-22 04:17:10
0001 #!/usr/bin/python 0002 import pykst as kst 0003 import numpy as np 0004 0005 def mandelbrot( h,w, maxit=10 ): 0006 '''Returns an image of the Mandelbrot fractal of size (h,w). 0007 ''' 0008 y,x = np.ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ] 0009 c = x+y*1j 0010 z = c 0011 divtime = maxit + np.zeros(z.shape, dtype=np.float64) 0012 0013 for i in xrange(maxit): 0014 z = z**2 + c 0015 diverge = z*np.conj(z) > 2**2 # who is diverging 0016 div_now = diverge & (divtime==maxit) # who is diverging now 0017 divtime[div_now] = i # note when 0018 z[diverge] = 2.0 # avoid diverging too much 0019 0020 return divtime 0021 0022 client=kst.Client("numpy_matrix_demo") 0023 np = mandelbrot(1000,1000) 0024 0025 M = client.new_editable_matrix(np) 0026 I = client.new_image(M) 0027 P = client.new_plot() 0028 P.add(I) 0029 0030 # print out name and size of all matrixes 0031 matrixes = client.get_matrix_list() 0032 for matrix in matrixes : 0033 print matrix.name(), matrix.width(), matrix.height() 0034 0035