Python 3 code ############################################## # 2D Newton's method set random generation # Polynomial f(z)=z**6+1 # (graphics module) ############################################## # specify the absolute path of mod graphics folder (depends on user's choice) import sys sys.path.append("/Users/strumia/Library/Python/3.6/site-packages/graphics/") from graphics import* # import graphics module import numpy as np # import numpy module import random # import random module Radius = .5 # set escape rate threshold Cx = 0.0 # set initial x parameter shift Cy = 0.0 # set initial y parameter shift Side = .8 # set square area side M = 300 # set side number of elementary squares N = 1 # set color map scale factor Num = 256*N # set number of cycles sT=2 # set step jump win = GraphWin("Newton's method set", 5*M/3,5*M/3) # set window title win.setBackground(color_rgb(230,220,10)) # set background color def rectCol(p,q,w): # define elementary cell Rect = Rectangle(Point(int(p-sT/2),int(q-sT/2)), Point(int(p+sT/2),int(q+sT/2))) Rect.draw(win).setOutline(color_rgb(np.int(255*np.sin(w)**2), np.int(255*np.cos(w)**2),np.int(255*np.cos(w/2)**2))) # Alternative values Cx 0.1747, 0.1747 Cy -.072,-1.072 # Side 0.0015, 0.00015 Num 1024 i = 1 # set non-zero index value while i > 0: # set random co-ordinates choice cycles p = random.randrange(1,M) q = random.randrange(1,M) Incx = - Side + 2*Side/M*q # set starting increment of x co-ordinate Incy = - Side + 2*Side/M*p # set starting increment of y co-ordinate x = Incx y = Incy w = 0 # set starting escape modulus value for n in range(1,Num): xx = 5*x/6.0 - x*(x*x*x*x - 10*x*x*y*y +5*y*y*y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/6.0 yy = 5*y/6.0 + y*(5*x*x*x*x - 10*x*x*y*y + y*y*y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/(x*x+y*y)/6.0 x = xx y = yy if (x-Cx)*(x-Cx) + (y-Cy)*(y-Cy) < Radius: # escape rate condition w = n/N # escape modulus normalization rectCol(int(M/3+q),int(M/3+p),int(w)) # plot elementary cell break # interrupt cycle