Project 5 - Fractal

390 days ago by mwolf7@fordham.edu

def fernx(x,y,rand): point=rand if(point<=.01): return .5 if(point<=.11): return -.15*x+.28*y+.575 if(point<=.23): return .2*x-.26*y+.4 return .85*x+.04*y+.075 def ferny(x,y,rand): point=rand if(point<=.01): return .16*y if(point<=.11): return .26*x+.24*y-.086 if(point<=.23): return .23*x+.22*y+.045 return -.04*x+.85*y+.18 array=[] xCoordinate=1 yCoordinate=1 array.append([xCoordinate, yCoordinate]) for x in range(9): r=random() xO=xCoordinate xCoordinate=fernx(xCoordinate,yCoordinate,r) yCoordinate=ferny(xO,yCoordinate,r) for x in range(50000): r=random() xO=xCoordinate xCoordinate=fernx(xCoordinate, yCoordinate, r) yCoordinate=ferny(xO, yCoordinate, r) array.append([xCoordinate, yCoordinate]) show (scatter_plot(array, markersize=.004)) 
       
 
       
def fernx(x,y,rand): point=rand if(point<=.01): return .5 if(point<=.11): return -.15*x+.18*y+.575 if(point<=.23): return .2*x-.26*y+.4 return .85*x+.02*y+.075 def ferny(x,y,rand): point=rand if(point<=.01): return .16*y if(point<=.11): return .26*x+.14*y-.086 if(point<=.23): return .23*x+.18*y+.045 return -.04*x+.85*y+.18 array=[] xCoordinate=1 yCoordinate=1 array.append([xCoordinate, yCoordinate]) for x in range(9): r=random() xO=xCoordinate xCoordinate=fernx(xCoordinate,yCoordinate,r) yCoordinate=ferny(xO,yCoordinate,r) for x in range(50000): r=random() xO=xCoordinate xCoordinate=fernx(xCoordinate, yCoordinate, r) yCoordinate=ferny(xO, yCoordinate, r) array.append([xCoordinate, yCoordinate]) show (scatter_plot(array, markersize=.004)) 
       
def mandelbrotPoints(imaginary,real): c=complex(real,imaginary) z=complex(0,0) for i in range(1,99): z=(z*z)+c if(abs(z)>2): return i return 0 array=[] for j in range(100): array.append([]) minimumReal=-1 maximumReal=.5 minimumImag=-.5 maximumImag=1 for y in range(400): c_imaginary=minimumImag+y*(maximumImag-minimumImag)/400 for x in range(600): c_real=minimumReal+x*(maximumReal-minimumReal)/600 m=mandelbrotPoints(c_imaginary,c_real) if(m>0): array[m].append([x,y]) plots=scatter_plot(array[0],markersize=.005,facecolor='green',edgecolor='blue') for k in range(1,99): from sage.plot.colors import green, blue if(len(array[k])>0): plots=plots+scatter_plot(array[k],markersize=.05,facecolor=(green.darker(fraction=10*k/100)).html_color(),edgecolor=(blue.darker(fraction=10*k/100)).html_color()) show(plots) 
       
def mandelbrotPoints(imaginary,real): c=complex(real,imaginary) z=complex(0,0) for i in range(1,99): z=(z*z)+c if(abs(z)>2): return i return 0 array=[] for j in range(100): array.append([]) minimumReal=-2 maximumReal=1 minimumImag=-1.5 maximumImag=1.5 for y in range(300): c_imaginary=minimumImag+y*(maximumImag-minimumImag)/300 for x in range(300): c_real=minimumReal+x*(maximumReal-minimumReal)/300 m=mandelbrotPoints(c_imaginary,c_real) if(m>0): array[m].append([x,y]) plots=scatter_plot(array[0],markersize=.55,facecolor='orange',edgecolor='orange') for k in range(1,99): colors=4*k/100 from sage.plot.colors import orange if(len(array[k])>0): plots=plots+scatter_plot(array[k],markersize=.55,facecolor=(orange.darker(fraction=colors)).html_color(),edgecolor=(orange.darker(fraction=colors)).html_color()) show(plots) 
       
def midPoint(point1,point2): return [(point1[0]+point2[0])/2,(point1[1]+point2[1])/2] def seirpinski(t1,t2,t3,x0,iterations): fractal=[t1,t2,t3] points=[x0] x=x0 for i in range(iterations): rand=floor(3*random()) x=midPoint(fractal[rand],x) points.append(x) return points s=seirpinski([0,0],[.5,.5],[1,0],[.2,.4],100000) show(list_plot(s,size=1)) 
       
def midPoint(point1,point2): return [(point1[0]-point2[0])/2,(point1[1]-point2[1])/2] def seirpinski(t1,t2,t3,t4,t5,x0,iterations): fractal=[t1,t2,t3,t4,t5] points=[x0] x=x0 for i in range(iterations): rand=floor(5*random()) x=midPoint(fractal[rand],x) points.append(x) return points s=seirpinski([0,0],[.5,.5],[1,0],[.5,.5],[.5,.5],[.2,.4],500000) show(list_plot(s,size=1)) 
       
def midPoint(point1,point2): return [(point1[0]-point2[0])/2,(point1[1]-point2[1])/2] def seirpinski(t1,t2,t3,x0,iterations): fractal=[t1,t2,t3] points=[x0] x=x0 for i in range(iterations): rand=floor(3*random()) x=midPoint(fractal[rand],x) points.append(x) return points s=seirpinski([0,0],[.5,.5],[1,0],[.2,.4],100000) show(list_plot(s,size=1))