Advertisement
Guest User

jkhs

a guest
Oct 31st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.27 KB | None | 0 0
  1. from cs1graphics import *
  2. from math import *
  3. from time import *
  4.  
  5.  
  6. ##################################
  7. ## get_number_of_edge()         ##
  8. ## Input : None                 ##
  9. ## Output : Integer value       ##
  10. ##################################
  11. def get_number_of_edge():
  12.     # ===============================================================
  13.     # Complete here
  14.     return int(raw_input("How many edges the polygon has? "))
  15.     # ===============================================================
  16.  
  17.  
  18. ##################################
  19. ## drawing_regular_polygon()    ##
  20. ## Input : Integer value        ##
  21. ## Output : Drawable object     ##
  22. ##################################
  23. def drawing_regular_polygon (e):
  24.     # ===============================================================
  25.     # Complete here
  26.     paper.setBackgroundColor("white")
  27.     paper.setTitle("drawing polygon")
  28.     c=Circle(50)
  29.     r=c.getRadius()
  30.     x0= paper.getWidth()
  31.     y0= paper.getHeight()
  32.     xc=x0/2
  33.     yc=y0/2
  34.     poly=Polygon()
  35.     for i in range (e):
  36.             #global e
  37.             x = xc + r*cos((2*pi/e)*(1+i))
  38.             y = yc + r* sin((2*pi/e)*(1+i))
  39.             poly.addPoint(Point(x, y), i+1)
  40.     paper.add(poly)
  41.     poly.moveTo(xc, yc)
  42.  
  43.     # ===============================================================
  44.  
  45.  
  46. ##################################
  47. ## animation()                  ##
  48. ## Input : Drawable object      ##
  49. ## Output : None                ##
  50. ##################################
  51. #def animation(p):
  52.     # ===============================================================
  53.     # Complete here
  54.  
  55.     # ===============================================================
  56.  
  57.    
  58. ##################################
  59. ## create_world()               ##
  60. ## Input : None                 ##
  61. ## Output : 'Canvas' object     ##
  62. ##################################
  63. #def create_world() :
  64.     # ===============================================================
  65.     # Complete here
  66.  
  67.     # ===============================================================
  68.    
  69.    
  70. ##################################
  71. ## make_beeper()                ##
  72. ## Input : None                 ##
  73. ## Output : 'Layer' object      ##
  74. ##################################    
  75. #def make_beeper() :
  76.     # ===============================================================
  77.     # Complete here
  78.  
  79.     # ===============================================================
  80.    
  81.    
  82. ##################################
  83. ## move_all_beepers()           ##
  84. ## Input : None                 ##
  85. ## Output : None                ##
  86. ##################################    
  87. #def move_all_beepers() :
  88.     # ===============================================================
  89.     # Complete here
  90.  
  91.     # ===============================================================
  92.    
  93.    
  94. ##################
  95. ## Main section ##
  96. ##################
  97.  
  98. # Drawing homework #1 - A regular polygon
  99. # ===============================================================
  100. paper = Canvas(500, 500)                      # make a 'Canvas Object'
  101. edge = get_number_of_edge()                   # get the number of edge
  102. poly = drawing_regular_polygon(edge)          # draw the regular polygon
  103. sleep(1)
  104. animation(poly)                               # animation of the regular polygon
  105. # ====================================s===========================
  106.  
  107. # Drawing homework #2 - Hubo's world
  108. # ===============================================================
  109. avenues, streets = 0, 0                       # the size of the Hubo's world
  110. all_beepers = Layer()                         # the main layer for all beepers
  111. leftmost, rightmost, upmost, downmost = 0, 0, 0, 0
  112.                                               # the outer positions of beepers
  113. canvas = create_world()                       # create world
  114. canvas.add(all_beepers)                       # add the main layer on the canvas
  115. all_beepers.setDepth(1)
  116.  
  117. while True:
  118.     all_beepers.add(make_beeper())            # draw a beeper and add the beeper on the main layer
  119.     yes_or_no = raw_input("Add more beepers?? (y or n) ")
  120.     if yes_or_no == 'n':                      # more beeper? or not
  121.         break
  122.    
  123. move_all_beepers()                            # move all beepers
  124. # ===============================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement