def mac_window(): # create Mac window big_rect = GRect(750, 500, x=5, y=5) big_rect.color = 'lightgrey' # create tool bar small_rect = GRect(750, 18, x=5, y=5) small_rect.filled = True small_rect.color = 'lightgrey' small_rect.fill_color = 'gainsboro' # create close window button oval_1 = GOval(12, 12, x=7, y=7) oval_1.filled = True oval_1.color = 'tomato' oval_1.fill_color = 'tomato' # create minimize window button oval_2 = GOval(12, 12, x=27, y=7) oval_2.filled = True oval_2.color = 'gold' oval_2.fill_color = 'gold' # create maximize window button oval_3 = GOval(12, 12, x=47, y=7) oval_3.filled = True oval_3.color = 'limegreen' oval_3.fill_color = 'limegreen' window.add(big_rect) window.add(small_rect) window.add(oval_1) window.add(oval_2) window.add(oval_3)
def build_blocks(): """ This function builds the blocks of the drawing """ block_1 = GRect(375, 80, x=20, y=330) block_1.filled = True block_1.color = 'firebrick' block_1.fill_color = 'firebrick' window.add(block_1) block_2 = GRect(375, 80, x=405, y=330) block_2.filled = True block_2.color = 'steelblue' block_2.fill_color = 'steelblue' window.add(block_2) block_3 = GRect(375, 80, x=20, y=420) block_3.filled = True block_3.color = 'goldenrod' block_3.fill_color = 'goldenrod' window.add(block_3) block_4 = GRect(375, 80, x=405, y=420) block_4.filled = True block_4.color = 'forestgreen' block_4.fill_color = 'forestgreen' window.add(block_4) block_5 = GRect(60, 40, x=720, y=120) block_5.filled = True block_5.color = 'dodgerblue' block_5.fill_color = 'dodgerblue' window.add(block_5) circle_1 = GOval(90, 90, x=20, y=170) circle_1.filled = True circle_1.color = 'blueviolet' circle_1.fill_color = 'blueviolet' window.add(circle_1)
def __draw_bricks(self): for i in range(self.__brick_rows): for j in range(self.__brick_cols): br1 = GRect(self.__brick_width, self.__brick_height) br1.filled = True br1.x = (self.__brick_width + self.__brick_spacing) * j br1.y = self.__brick_offset + (self.__brick_height + self.__brick_spacing) * i rows_in_sec = self.__brick_rows / BRICK_SECTION if i <= rows_in_sec - 1: # Section 1 br1.fill_color = 'red' br1.color = 'red' elif rows_in_sec - 1 < i <= rows_in_sec * 2 - 1: # Section 2 br1.fill_color = 'orange' br1.color = 'orange' elif rows_in_sec * 2 - 1 < i <= rows_in_sec * 3 - 1: # Section 3 br1.fill_color = 'yellow' br1.color = 'yellow' elif rows_in_sec * 3 - 1 < i <= rows_in_sec * 4 - 1: # Section 4 br1.fill_color = 'green' br1.color = 'green' else: # Section 5 and so on. br1.fill_color = 'lightseagreen' br1.color = 'lightseagreen' self.__window.add(br1)
def eiffel_tower_bottom(): """ This function will draw the eiffel tower's bottom on the canvas. """ bottom = GRect(398, 100, x=401, y=705) bottom.filled = True bottom.fill_color = 'gray' bottom.color = 'gray' window.add(bottom) for i in range(20): rect = GRect(90-(i*5), 10, x=401, y=700+i*5) rect.filled=True rect.fill_color = 'white' rect.color = 'white' window.add(rect) for i in range(20): rect = GRect(90-(i*5), 10, x=709+i*5, y=700+i*5) rect.filled = True rect.fill_color = 'white' rect.color = 'white' window.add(rect) arch = GOval(150, 150, x=523, y=730) arch.filled = True arch.fill_color = 'white' arch.color = 'white' window.add(arch)
def arch_triomphe_body(): """ This function will draw the body part of the Arch de Triomphe. """ body = GRect(280,280, x=860, y=520) body.filled = True body.fill_color = 'white' body.color = 'white' window.add(body) arch = GOval(170,290,x=915,y=610) arch.filled = True arch.fill_color = 'red' arch.color = 'red' window.add(arch) middle_line = GRect(280, 15, x=860, y=660) middle_line.filled = True middle_line.fill_color = 'red' middle_line.color = 'red' window.add(middle_line) upper_line = GRect(280, 15, x=860, y=600) upper_line.filled = True upper_line.fill_color = 'red' upper_line.color = 'red' window.add(upper_line) top_line = GRect(280, 20, x=860, y=550) top_line.filled = True top_line.fill_color = 'red' top_line.color = 'red' window.add(top_line)
def background(w): for i in range(127): 'red to yellow' r = GRect(2, 500, x=0 + i * 2, y=0) r.fill_color = (255, 0 + i * 2, 0) r.color = (255, 0 + i * 2, 0) r.filled = True w.add(r) for k in range(127): 'yellow to green' y = GRect(2, 500, x=254 + k * 2, y=0) y.fill_color = (255 - k * 2, 255, 0) y.color = (255 - k * 2, 255, 0) y.filled = True w.add(y) for j in range(127): 'green to blue' b = GRect(2, 500, x=508 + j * 2, y=0) b.fill_color = (0, 255 - j * 2, 0 + j * 2) b.color = (0, 255 - j * 2, 0 + j * 2) b.filled = True w.add(b) for a in range(127): 'blue to purple' p = GRect(2, 500, x=762 + a * 2, y=0) p.fill_color = (0 + a * 2, 0, 255) p.color = (0 + a * 2, 0, 255) p.filled = True w.add(p)
def build_s(): # Create word: S. global window rect_l = 100 rect_s = 20 rect1 = GRect(rect_l, rect_s, x=100, y=150) rect2 = GRect(rect_s, rect_l, x=100, y=150) rect3 = GRect(rect_l, rect_s, x=100, y=230) rect4 = GRect(rect_s, rect_l, x=180, y=230) rect5 = GRect(rect_l, rect_s, x=100, y=310) rect1.filled = True rect1.fill_color = 'tomato' rect1.color = 'tomato' rect2.filled = True rect2.fill_color = 'tomato' rect2.color = 'tomato' rect3.filled = True rect3.fill_color = 'tomato' rect3.color = 'tomato' rect4.filled = True rect4.fill_color = 'tomato' rect4.color = 'tomato' rect5.filled = True rect5.fill_color = 'tomato' rect5.color = 'tomato' window.add(rect1) window.add(rect2) window.add(rect3) window.add(rect4) window.add(rect5)
def build_karel4(): """ This function builds the fourth karel """ add = 3 head = GOval(80, 55, x=190 + 120 * add, y=167) head.filled = True head.color = 'black' head.fill_color = 'gray' window.add(head) hair1 = GLine(590, 167, 590, 161) hair2 = GLine(588, 168, 585, 162) hair3 = GLine(592, 168, 595, 162) hair4 = GLine(585, 168, 582, 162) hair5 = GLine(595, 168, 598, 162) window.add(hair1) window.add(hair2) window.add(hair3) window.add(hair4) window.add(hair5) r_eye = GOval(14, 14, x=212 + 120 * add, y=189) r_eye.filled = True r_eye.color = 'black' r_eye.fill_color = 'blue' window.add(r_eye) l_eye = GOval(14, 14, x=235 + 120 * add, y=189) l_eye.filled = True l_eye.color = 'black' l_eye.fill_color = 'blue' window.add(l_eye) hands = GRect(105, 45, x=177 + 120 * add, y=237) hands.filled = True hands.color = 'black' hands.fill_color = 'lime' window.add(hands) body_1 = GRect(60, 65, x=201 + 120 * add, y=223) body_1.filled = True body_1.color = 'black' body_1.fill_color ='blue' window.add(body_1) body_2 = GRect(80, 60, x=190 + 120 * add, y=230) body_2.filled = True body_2.color = 'black' body_2.fill_color = 'blue' window.add(body_2) r_foot = GOval(29, 24, x=190 + 120 * add, y=290) r_foot.filled = True r_foot.color = 'black' r_foot.fill_color = 'red' window.add(r_foot) l_foot = GOval(29, 24, x=241 + 120 * add, y=290) l_foot.filled = True l_foot.color = 'black' l_foot.fill_color = 'red' window.add(l_foot) label = GRect(20, 20, x=218+120*add, y=130) label.filled = True label.fill_color = 'forestgreen' label.color = 'forestgreen' window.add(label)
def eiffel_tower_middle_top(): """ This function will draw the middle upper part of the Eiffel tower """ big_square = GRect(130, 245, x=535, y=320) big_square.filled = True big_square.fill_color = 'gray' big_square.color = 'gray' window.add(big_square) for i in range(30): rect = GRect(30, 30, x=538-i*1.15, y=250+i*10) rect.filled = True rect.fill_color = 'white' rect.color = 'white' window.add(rect) for i in range(30): rect = GRect(30, 30, x=632 + i * 1.15, y=250 + i * 10) rect.filled = True rect.fill_color = 'white' rect.color = 'white' window.add(rect) for i in range(14): triangle = GRect(40-i, 13, x=570+i, y=545-i*13) triangle.filled = True triangle.fill_color = 'white' triangle.color = 'white' window.add(triangle) for i in range(14): triangle = GRect(40-i, 13, x=593-i/2, y=545-i*13) triangle.filled = True triangle.fill_color = 'white' triangle.color = 'white' window.add(triangle)
def build_karel1(): """ This function builds the first karel """ head = GOval(80, 55, x=190, y=167) head.filled = True head.color = 'black' head.fill_color = 'gray' window.add(head) r_eye = GRect(13, 13, x=212, y=189) r_eye.filled = True r_eye.color = 'black' r_eye.fill_color = 'blue' window.add(r_eye) l_eye = GRect(13, 13, x=235, y=189) l_eye.filled = True l_eye.color = 'black' l_eye.fill_color = 'blue' window.add(l_eye) r_eyeb = GLine(212, 185, 225, 185) window.add(r_eyeb) l_eyeb = GLine(235, 185, 248, 185) window.add(l_eyeb) hands = GRect(105, 45, x=177, y=237) hands.filled = True hands.color = 'black' hands.fill_color = 'lime' window.add(hands) body_1 = GRect(60, 65, x=201, y=223) body_1.filled = True body_1.color = 'black' body_1.fill_color = 'blue' window.add(body_1) body_2 = GRect(80, 60, x=190, y=230) body_2.filled = True body_2.color = 'black' body_2.fill_color = 'blue' window.add(body_2) r_foot = GOval(29, 24, x=190, y=290) r_foot.filled = True r_foot.color = 'black' r_foot.fill_color = 'red' window.add(r_foot) l_foot = GOval(29, 24, x=241, y=290) l_foot.filled = True l_foot.color = 'black' l_foot.fill_color = 'red' window.add(l_foot) label = GPolygon() label.add_vertex((230, 130)) label.add_vertex((218, 150)) label.add_vertex((242, 150)) label.filled = True label.fill_color = 'firebrick' label.color = 'firebrick' window.add(label)
def loading_bar(): rect = GRect(300, 40, x=255, y=300) rect.color = 'lightgrey' window.add(rect) for i in range(0, 200, 25): rect_loading = GRect(20, 35, x=258 + i, y=303) rect_loading.filled = True rect_loading.color = 'darkgrey' rect_loading.fill_color = 'darkgrey' window.add(rect_loading)
def draw(mouse): stroke = GRect(SIZE, SIZE, x = mouse.x-SIZE/2, y = mouse.y-SIZE/2) if (mouse.x -SIZE/2) < (WINDOW_WIDTH/2): stroke.filled = True stroke.color = COLOR stroke.fill_color = COLOR else: stroke.filled = True stroke.color = COLOR2 stroke.fill_color = COLOR2 window.add(stroke)
def back(window): """ :param window:window """ blue = GRect(800, 500) blue.color = 'PaleTurquoise' blue.filled = True blue.fill_color = 'PaleTurquoise' window.add(blue) back = GOval(300, 300, x=100, y=50) back.color = 'white' back.filled = True back.fill_color = 'gray' window.add(back) back_1 = GOval(150, 150) back_1.color = 'gray' back_1.filled = True back_1.fill_color = 'gray' window.add(back_1) back_2 = GOval(150, 150) back_2.color = 'gray' back_2.filled = True back_2.fill_color = 'gray' window.add(back_2, x=150 + 200, y=0) neck = GRect(50, 70, x=back.width // 2 + 70, y=300) neck.color = 'gray' neck.filled = True neck.fill_color = 'gray' window.add(neck) body1 = GOval(400, 300, x=50, y=360) body1.color = 'pink' body1.filled = True body1.fill_color = 'pink' window.add(body1) body2 = GOval(50, 100, x=150, y=400) body2.color = 'Light yellow' body2.filled = True body2.fill_color = 'Light yellow' window.add(body2) body3 = GOval(50, 100, x=250, y=400) body3.color = 'Light yellow' body3.filled = True body3.fill_color = 'Light yellow' window.add(body3) tree1 = GRect(70, 300, x=600, y=230) tree1.color = 'PaleGoldenrod' tree1.filled = True tree1.fill_color = 'PaleGoldenrod' window.add(tree1) tree2 = GOval(170, 170, x=550, y=150) tree2.color = 'Pale green' tree2.filled = True tree2.fill_color = 'Pale green' window.add(tree2)
def set_game(self): """ This method set up the starting interface for the game. Including materials such as: paddle, window, score sign and bricks. """ # Create a paddle. self.window.add(self.paddle) # Center a filled ball in the graphical window. self.window.add(self.ball) # Build the score sign self.score_sign = GLabel(f'SCORE : {self.__score}') self.score_sign.color = 'crimson' self.score_sign.font = 'Mamelon-20' self.window.add(self.score_sign, x=8, y=self.window.height - 8) # Build lives sign self.live_2.filled = True self.live_2.color = 'crimson' self.live_2.fill_color = 'crimson' self.window.add(self.live_2) self.live_1.filled = True self.live_1.color = 'crimson' self.live_1.fill_color = 'crimson' self.window.add(self.live_1) # Draw bricks. for i in range(BRICK_ROWS): for j in range(BRICK_COLS): brick = GRect(BRICK_WIDTH, BRICK_HEIGHT, x=i * (BRICK_WIDTH + BRICK_SPACING), y=BRICK_OFFSET + j * (BRICK_HEIGHT + BRICK_SPACING)) brick.filled = True if j == 0 or j == 1: brick.color = 'darkslategrey' brick.fill_color = 'darkslategrey' elif j == 2 or j == 3: brick.color = 'teal' brick.fill_color = 'teal' elif j == 4 or j == 5: brick.color = 'cadetblue' brick.fill_color = 'cadetblue' elif j == 6 or j == 7: brick.color = 'lightseagreen' brick.fill_color = 'lightseagreen' else: brick.color = 'mediumturquoise' brick.fill_color = 'mediumturquoise' self.window.add(brick)
def build_karel3(): """ This function builds the third karel """ add = 2 head = GOval(80, 55, x=190 + 120 * add, y=167) head.filled = True head.color = 'black' head.fill_color = 'gray' window.add(head) r_eye = GRect(13, 13, x=212 + 120 * add, y=189) r_eye.filled = True r_eye.color = 'black' r_eye.fill_color = 'blue' window.add(r_eye) l_eye = GRect(13, 13, x=235 + 120 * add, y=189) l_eye.filled = True l_eye.color = 'black' l_eye.fill_color = 'blue' window.add(l_eye) hands = GRect(105, 45, x=177 + 120 * add, y=237) hands.filled = True hands.color = 'black' hands.fill_color = 'lime' window.add(hands) body_1 = GRect(60, 65, x=201 + 120 * add, y=223) body_1.filled = True body_1.color = 'black' body_1.fill_color = 'blue' window.add(body_1) body_2 = GRect(80, 60, x=190 + 120 * add, y=230) body_2.filled = True body_2.color = 'black' body_2.fill_color = 'blue' window.add(body_2) r_foot = GOval(29, 24, x=190 + 120 * add, y=290) r_foot.filled = True r_foot.color = 'black' r_foot.fill_color = 'red' window.add(r_foot) l_foot = GOval(29, 24, x=241 + 120 * add, y=290) l_foot.filled = True l_foot.color = 'black' l_foot.fill_color = 'red' window.add(l_foot) label = GOval(22, 22, x=218+120*add, y=130) label.filled = True label.fill_color = 'goldenrod' label.color = 'goldenrod' window.add(label)
def draw_background_hill(hill_num, surface_y): """ draw random hills, random numbers of hill and random locations. """ hill_bottom_x_start = random.randint(0, window.width // hill_num) for i in range(hill_num): random_hill_height = random.randint(3, 9) * PIXEL_SIZE hill_wide = 2 * random_hill_height for h in range(random_hill_height // PIXEL_SIZE): for w in range(h * 2): hill_square = GRect(PIXEL_SIZE, PIXEL_SIZE) hill_square.filled = True hill_square.fill_color = (HILL_R, HILL_G, HILL_B) hill_square.color = (HILL_R, HILL_G, HILL_B) window.add(hill_square, (hill_bottom_x_start + hill_wide) // 2 - h * PIXEL_SIZE + w * PIXEL_SIZE, (surface_y - random_hill_height) + h * PIXEL_SIZE) if i + 1 < hill_num: if hill_bottom_x_start + hill_wide > window.width: hill_bottom_x_start = 0 hill_bottom_x_start = random.randint( hill_bottom_x_start + hill_wide, ((window.width - (hill_bottom_x_start + hill_wide)) // (hill_num - (i + 1)) + hill_bottom_x_start + hill_wide))
def karel_neck(): # Build Karel's neck. global neck neck = GRect(30, 4, x=235, y=58) neck.filled = True neck.color = 'blue' window.add(neck)
def draw_rect(level, width, center_x, center_y): if level == 0: pass else: # rect = GRect(width, width, x = center_x - width/2, y = center_y - width/2) # rect.filled = True # rect.color = 'black' # rect.fill_color = 'snow' # window.add(rect) # # # upper left # draw_rect(level - 1, width/2, center_x - width/2, center_y - width/2) # # upper right # draw_rect(level - 1, width / 2, center_x + width / 2, center_y - width / 2) # # down left # draw_rect(level - 1, width / 2, center_x - width / 2, center_y + width / 2) # # down right # draw_rect(level - 1, width / 2, center_x + width / 2, center_y + width / 2) rect = GRect(width, width, x=center_x - width / 2, y=center_y - width / 2) rect.filled = True rect.color = 'black' rect.fill_color = 'snow' # upper left draw_rect(level - 1, width / 2, center_x - width / 2, center_y - width / 2) # down right draw_rect(level - 1, width / 2, center_x + width / 2, center_y + width / 2) window.add(rect) # upper right draw_rect(level - 1, width / 2, center_x + width / 2, center_y - width / 2) # down left draw_rect(level - 1, width / 2, center_x - width / 2, center_y + width / 2)
def add_stars(): """ adding stars on the sky. """ star_num = SIZE star_x_start = 0 star_x_end = window.width star_y_start = 0 star_y_end = window.height - window.height // 5 * 2 - 6 * SIZE * PIXEL_SIZE + 3 * PIXEL_SIZE for i in range(star_num): random_x = random.randint(star_x_start + PIXEL_SIZE, star_x_end - PIXEL_SIZE) random_y = random.randint(star_y_start + PIXEL_SIZE, star_y_end - PIXEL_SIZE) for x in range(3): for y in range(3): # build a star in "+" shaped. if (x == 0 and y == 0) or (x == 2 and y == 0) or ( x == 0 and y == 2) or (x == 2 and y == 2): pass else: star = GRect(PIXEL_SIZE // 2, PIXEL_SIZE // 2) star.filled = True star.color = (240, 230, 140) star.fill_color = (240, 230, 140) window.add(star, random_x + (x - 1) * PIXEL_SIZE, random_y + (y - 1) * PIXEL_SIZE)
def put_bricks(self): """ This method creates the bricks we needed. """ x_point = 0 y_point = 0 + self.b_offset color = 'red' # Loop over how many bricks we needed. for i in range(self.row): for j in range(self.col): brick = GRect(self.b_width, self.b_height) brick.filled = True brick.color = color brick.fill_color = color self.window.add(brick, x_point, y_point) x_point += self.b_width x_point += self.b_space y_point += self.b_height y_point += self.b_space x_point = 0 # The color in each row. if i == 1: color = 'orange' if i == 3: color = 'yellow' if i == 5: color = 'green' if i == 7: color = 'blue'
def add_rainbow(window): """This function add a rainbow to the window""" # initial setting for the rainbow size_ini_cir = 600 x_cir = WINDOW_WIDTH * 0.5 y_cir = WINDOW_HEIGHT * 0.85 int_cir = 50 # plot the concentric circles for i in range(len(RAINBOW_COLOR_LIST)): size_cir = size_ini_cir - int_cir * i circle = GOval(size_cir, size_cir, x=x_cir - size_cir / 2, y=y_cir - size_cir / 2) circle.filled = True circle.color = RAINBOW_COLOR_LIST[i] circle.fill_color = RAINBOW_COLOR_LIST[i] window.add(circle) # block the lower part of the circles by overlaying a box rect = GRect(size_ini_cir, size_ini_cir / 2, x=x_cir - size_ini_cir / 2, y=y_cir) rect.filled = True rect.color = RAINBOW_COLOR_LIST[-1] rect.fill_color = RAINBOW_COLOR_LIST[-1] window.add(rect)
def add_heart(window): """This function add a heart to the window""" # initial settings for plotting the heart y_max, y_min = 525, 85 # 520, 90 y_interval = 70.83 # 71.6 y_list = [y_min + i * y_interval for i in range(len(COLOR_LIST) + 1)] # start to draw a heart for y in range(0, WINDOW_HEIGHT, INTERVAL): for x in range(0, WINDOW_WIDTH, INTERVAL): # equation for heart cx = (x - X_SHIFT) * X_SCALE cy = (y - Y_SHIFT) * Y_SCALE love = ((cx**2 + cy**2 - 1)**3) - (cx**2 * cy**3) # plot the squares inside the heart if love < 0: for i in range(len(y_list)): if i != len(y_list) - 1: if y_list[i] < y <= y_list[i + 1]: square = GRect(SIZE, SIZE, x=x - SIZE / 2, y=y - SIZE / 2) square.filled = True square.color = COLOR_LIST[i] square.fill_color = COLOR_LIST[i] window.add(square)
def eiffel_tower_top(): """ This function will draw the top part of the Eiffel tower. """ for i in range(3): square = GRect((65-i*15), 25, x=568+(i*7), y=290-(i*30)) square.filled = True square.fill_color = 'gray' square.color = 'gray' window.add(square) pin= GRect(10, 50, x=595, y=175) pin.filled = True pin.fill_color = 'gray' pin.color = 'gray' window.add(pin)
def cannon(self, hull): if random.randrange(0, 8) > 6: laser1 = GRect(self.ball_radius * 0.5, self.ball_radius * 3) laser2 = GRect(self.ball_radius * 0.5, self.ball_radius * 3) laser1.filled = True laser1.fill_color = "red" laser1.color = "red" laser2.filled = True laser2.fill_color = "red" laser2.color = "red" self.window.add(laser1, x=hull.x, y=hull.y) self.window.add(laser2, x=hull.x + hull.width, y=hull.y) for i in range(50): laser1.move(0, 10) laser2.move(0, 10) pause(10)
def refill_bricks(self): """ Refill the bricks when game restart. """ for x in range(self.__brick_rows): for y in range(self.__brick_cols): __x_coordinate = x * (self.__brick_width + self.__brick_spacing) __y_coordinate = self.__brick_offset + y * (self.__brick_height + self.__brick_spacing) if self.__window.get_object_at(__x_coordinate, __y_coordinate) is None: __brick = GRect(self.__brick_width, self.__brick_height) __brick.filled = True if y < 2: __brick.fill_color = (RED_R, RED_G, RED_B) elif y < 4: __brick.fill_color = (ORANGE_R, ORANGE_G, ORANGE_B) elif y < 6: __brick.fill_color = (YELLOW_R, YELLOW_G, YELLOW_B) elif y < 8: __brick.fill_color = (GREEN_R, GREEN_G, GREEN_B) else: __brick.fill_color = (BLUE_R, BLUE_G, BLUE_B) __brick.color = (0, 0, 0) # if y == 9: (This line switch for building only one row of bricks.) # self.__window.add(__brick, __x_coordinate, __y_coordinate) # self.__brick_nums += 1 self.__window.add(__brick, __x_coordinate, __y_coordinate) self.__brick_nums += 1
def breed(self): """ This method create three circle and one rectangle to compose a cloud shape. Every time the cloud shape will be displayed in random position of window. """ dx = random.randint(10, window.width - 10) dy = random.randint(10, window.height - 10) rect = GRect(70, 30) rect.color = 'mintcream' rect.filled = True rect.fill_color = 'mintcream' self.list.append(rect) for i in range(3): circle = GOval(60, 60) circle.color = 'mintcream' circle.filled = True circle.fill_color = 'mintcream' self.list.append(circle) window.add(self.list[0], window.width + 45 + dx, 55 + dy) window.add(self.list[1], window.width + 10 + dx, 25 + dy) window.add(self.list[2], window.width + 45 + dx, 0 + dy) window.add(self.list[3], window.width + 80 + dx, 25 + dy)
def flag(): """ This function will draw the flag of France. """ # blue part blue_flag=GRect(400, 800, x=0, y=0) blue_flag.filled=True blue_flag.fill_color='dark_blue' blue_flag.color='dark_blue' window.add(blue_flag) # red part red_flag=GRect(400, 800, x=800, y=0) red_flag.filled = True red_flag.fill_color = 'red' red_flag.color = 'red' window.add(red_flag)
def main(): # background background_color = ['ivory', 'lightblue', 'skyblue'] for i in range(0, 3): background = GRect(window.width, window.height / 3, x=0, y=window.height / 3 * i) background.filled = True background.fill_color = '' + background_color[i] background.color = '' + background_color[i] window.add(background) # pyramid pyramid_color = [ 'saddlebrown', 'darkgoldenrod', 'goldenrod', 'orange', 'gold', 'palegoldenrod', 'lemonchiffon' ] for i in range(0, 7): # pyramid Grect pyramid = GRect(FIRST_X - REDUCE * i, FIRST_Y, x=5 + REDUCE / 2 * i, y=window.height - FIRST_Y * (1 + i)) pyramid.filled = True pyramid.fill_color = '' + pyramid_color[i] window.add(pyramid) # pyramid GLabel # pyramid_label = GLabel('STAGE '+str(i+1), x=260, y=window.height - FIRST_Y * i -10) # pyramid_label.font = '-24' # pyramid_label.color = 'darkgrey' # window.add(pyramid_label) # flag flagstaff = GRect(5, 100, x=280, y=50) flagstaff.filled = True flagstaff.fill_color = 'brown' window.add(flagstaff) flag = GRect(100, 40, x=285, y=50) flag.filled = True flag.fill_color = 'silver' window.add(flag) flag_label = GLabel('GOAL!!!', x=290, y=85) flag_label.font = '-26' flag_label.color = 'red' window.add(flag_label) # sun sun() # robot robot_face() robot_body()
def arch_triomphe_deco(): """ This function will add the deco part on the Arch de Triomphe. """ # middle circle part middle_circle = GOval(60, 60, x=970, y=580) middle_circle.filled = True middle_circle.fill_color = 'white' middle_circle.color = 'white' window.add(middle_circle) middle_circle_inside = GOval(40, 40, x=980, y=590) middle_circle_inside.filled = True middle_circle_inside.fill_color = 'red' middle_circle_inside.color = 'red' window.add(middle_circle_inside) # dots on the roof for i in range(9): small_dot = GOval(15,15, x=875+(i*30), y=528) small_dot.filled = True small_dot.fill_color = 'red' small_dot.color = 'red' window.add(small_dot) # small squares on the pillar for i in range(2): small_square = GRect(20, 20, x=890+(i*200), y=630) small_square.filled = True small_square.fill_color = 'red' small_square.color = 'red' window.add(small_square) # ovals on the pillar for i in range(2): small_oval = GOval(20,50, x=875+(i*230), y=690) small_oval.filled = True small_oval.fill_color = 'red' small_oval.color = 'red' window.add(small_oval) # lines on the pillar for i in range(2): small_line = GRect(30, 5, x=870 + (i * 230), y=750) small_line.filled = True small_line.fill_color = 'red' small_line.color = 'red' window.add(small_line)
def create_bricks(self, brick_offset=BRICK_OFFSET, brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT, brick_spacing=BRICK_SPACING): d_y = brick_offset color = ['#96514d', '#d3381c', '#2c4f54', '#00a381', '#008899', '#3e62ad', '#316745', '#028760', '#fabf14', '#274a78'] for i in range(self.brick_rows): c = color[random.randint(0, 9)] d_x = 0 for j in range(self.brick_cols - 1): brick = GRect(brick_width, brick_height, x=d_x, y=d_y) brick.filled = True brick.color = c brick.fill_color = brick.color self.window.add(brick) d_x = d_x + brick_width + brick_spacing brick = GRect(brick_width, brick_height, x=d_x, y=d_y) brick.filled = True brick.color = c brick.fill_color = brick.color self.window.add(brick) d_y = d_y + brick_height + brick_spacing