Python 3 code ################################# # Sequential sphere generation # by Paramteric equations # (graphics module) #############################7#### # 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 x = 200 # set x initial value y = 100 # set y initial value z = 100 # set z initial value bgColor = "white" # set background color title = "Sphere" # set window title winWidth = 400 # set window width winHeight = 400 # set window height def pBall(x,y,z,rayBall,colBall): # def cell function X = x Y = y Circle(Point(X,Y),rayBall) Circle(Point(X,Y),rayBall).draw(win).setFill(colBall) win = GraphWin(title, winWidth, winHeight) # define window win.setBackground(bgColor) # set background color n = 126 # set number of angular steps x0 = np.int(.5*winWidth) # set sphere center x co-ordinate y0 = np.int(.5*winHeight) # set sphere center y co-ordinate z0 = 0 # set sphere center z co-ordinate R = 150 # set sphere radius value t = 0 # set initial t parameter value u = 0 # set initial u parameter value # def 3D rendering functions on 2D plane def xx(t): return R*np.sin(np.pi-np.pi*t/n) def yy(t): return R*np.cos(np.pi-np.pi*t/n) def co(u): return np.cos(2*np.pi*u/n) def si(u): return np.sin(2*np.pi*u/n) def x(t,u): return xx(t)*co(u) def z(t,u): return yy(t)*si(u) # plot sphere point by point by spherical co-ordinates parametric equations for u in range(0,n,1): for t in range(0,n,2): pBall(x0 + x(t,u),y0 - yy(t),0,4, color_rgb(255,2*t,2*u)) win.getMouse() # wait for mouse click win.close() # close window