Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cs1graphics import *
- from math import *
- from time import *
- ##################################
- ## get_number_of_edge() ##
- ## Input : None ##
- ## Output : Integer value ##
- ##################################
- def get_number_of_edge():
- # ===============================================================
- # Complete here
- return int(raw_input("How many edges the polygon has? "))
- # ===============================================================
- ##################################
- ## drawing_regular_polygon() ##
- ## Input : Integer value ##
- ## Output : Drawable object ##
- ##################################
- def drawing_regular_polygon (e):
- # ===============================================================
- # Complete here
- paper.setBackgroundColor("white")
- paper.setTitle("drawing polygon")
- c=Circle(50)
- r=c.getRadius()
- x0= paper.getWidth()
- y0= paper.getHeight()
- xc=x0/2
- yc=y0/2
- poly=Polygon()
- for i in range (e):
- #global e
- x = xc + r*cos((2*pi/e)*(1+i))
- y = yc + r* sin((2*pi/e)*(1+i))
- poly.addPoint(Point(x, y), i+1)
- paper.add(poly)
- poly.moveTo(xc, yc)
- # ===============================================================
- ##################################
- ## animation() ##
- ## Input : Drawable object ##
- ## Output : None ##
- ##################################
- #def animation(p):
- # ===============================================================
- # Complete here
- # ===============================================================
- ##################################
- ## create_world() ##
- ## Input : None ##
- ## Output : 'Canvas' object ##
- ##################################
- #def create_world() :
- # ===============================================================
- # Complete here
- # ===============================================================
- ##################################
- ## make_beeper() ##
- ## Input : None ##
- ## Output : 'Layer' object ##
- ##################################
- #def make_beeper() :
- # ===============================================================
- # Complete here
- # ===============================================================
- ##################################
- ## move_all_beepers() ##
- ## Input : None ##
- ## Output : None ##
- ##################################
- #def move_all_beepers() :
- # ===============================================================
- # Complete here
- # ===============================================================
- ##################
- ## Main section ##
- ##################
- # Drawing homework #1 - A regular polygon
- # ===============================================================
- paper = Canvas(500, 500) # make a 'Canvas Object'
- edge = get_number_of_edge() # get the number of edge
- poly = drawing_regular_polygon(edge) # draw the regular polygon
- sleep(1)
- animation(poly) # animation of the regular polygon
- # ====================================s===========================
- # Drawing homework #2 - Hubo's world
- # ===============================================================
- avenues, streets = 0, 0 # the size of the Hubo's world
- all_beepers = Layer() # the main layer for all beepers
- leftmost, rightmost, upmost, downmost = 0, 0, 0, 0
- # the outer positions of beepers
- canvas = create_world() # create world
- canvas.add(all_beepers) # add the main layer on the canvas
- all_beepers.setDepth(1)
- while True:
- all_beepers.add(make_beeper()) # draw a beeper and add the beeper on the main layer
- yes_or_no = raw_input("Add more beepers?? (y or n) ")
- if yes_or_no == 'n': # more beeper? or not
- break
- move_all_beepers() # move all beepers
- # ===============================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement