#*********************vspiral.py************************* # # William Baker # # usage: python vspiral.py --iterations x --percentage y # # where: # # x = number of iterations (integer) # y = percentage expressed as a decimal (i.e. .5 not 50) #********************************************************* from visual import * from math import * from getopt import * import sys numboxes=10 percentage=.5 def draw(): global numboxes, percentage corner1=[-5.0,-5.0] corner2=[5.0,-5.0] corner3=[5.0,5.0] corner4=[-5.0,5.0] for j in range(0,numboxes): curve(pos=[(corner1[0],corner1[1],0), ((corner1[0]*(1-percentage)+corner2[0]*percentage), (corner1[1]*(1-percentage)+corner2[1]*percentage),0)], color=(0,1,1)) curve(pos=[((corner1[0]*(1-percentage)+corner2[0]*percentage), (corner1[1]*(1-percentage)+corner2[1]*percentage),0), (corner2[0],corner2[1],0),(corner3[0],corner3[1],0), (corner4[0],corner4[1],0),(corner1[0],corner1[1],0)], color=(.75,.75,.75)) temp1=[(corner1[0]*(1-percentage)+corner2[0]*percentage), (corner1[1]*(1-percentage)+corner2[1]*percentage)] temp2=[(corner2[0]*(1-percentage)+corner3[0]*percentage), (corner2[1]*(1-percentage)+corner3[1]*percentage)] temp3=[(corner3[0]*(1-percentage)+corner4[0]*percentage), (corner3[1]*(1-percentage)+corner4[1]*percentage)] temp4=[(corner4[0]*(1-percentage)+corner1[0]*percentage), (corner4[1]*(1-percentage)+corner1[1]*percentage)] corner1=temp1 corner2=temp2 corner3=temp3 corner4=temp4 def main(): global numboxes, percentage try: opts, args = getopt(sys.argv[1:],"",['iterations=', 'percentage=']) except GetoptError: sys.exit(1) numboxes=int((opts[0])[1]) percentage=float((opts[1])[1]) draw() main()