Beispiel #1
0
def house_background():
    night_sky = GRect(WINDOW_WIDTH, WINDOW_HEIGHT)
    obj_fill_color_add(night_sky, "darkgrey")
    house_obj = [None] * 3
    # room floor
    house_obj[0] = GPolygon()
    polygon_helper(house_obj[0], "oldlace", (300, 750), (1500, 750), (1500, 900), (  0, 900))
    # left wall
    house_obj[1] = GPolygon()
    polygon_helper(house_obj[1], "oldlace", (  0, -20), ( 300,  50), ( 300, 750), (  0, 900))
    # ceiling
    house_obj[2] = GPolygon()
    polygon_helper(house_obj[2], "oldlace", (  0, -20), (1500,   0), (1500,  50), (300,  50))
Beispiel #2
0
def toes():
    toe0 = GPolygon()
    toe0.add_vertex((420, 555))
    toe0.add_vertex((475, 555))
    toe0.add_vertex((475, 525))
    toe0.filled = True
    toe0.fill_color = 'ivory'
    window.add(toe0)
    toe1 = GPolygon()
    toe1.add_vertex((525, 555))
    toe1.add_vertex((580, 555))
    toe1.add_vertex((580, 525))
    toe1.filled = True
    toe1.fill_color = 'ivory'
    window.add(toe1)
def sierpinski_triangle(order, length, upper_left_x, upper_left_y):
	"""
	:param order: decide how many layer of sierpinski triangle
	:param length: length of triangle's side
	:param upper_left_x: x coordinate of first triangle's start point
	:param upper_left_y: y coordinate of first triangle's start point
	:return: sierpinski triangle of given order
	"""

	if order == 0:
		pass
	else:
		triangle = GPolygon()
		triangle.add_vertex((upper_left_x, upper_left_y))
		triangle.add_vertex((upper_left_x + length, upper_left_y))
		triangle.add_vertex((upper_left_x + 0.5 * length, upper_left_y + 0.866 * length))

		circle = GOval(math.sqrt(3) * length / 3, math.sqrt(3) * length /3, x=upper_left_x + 0.5 * length - math.sqrt(3) * length /6, y=upper_left_y )
		circle.filled = True
		circle.fill_color ='snow'


		window.add(circle)
		window.add(triangle)


		sierpinski_triangle(order - 1, length/2, upper_left_x, upper_left_y)
		sierpinski_triangle(order - 1, length/2, upper_left_x + 0.25 * length, upper_left_y + 0.433 * length)
		sierpinski_triangle(order - 1, length/2, upper_left_x + 0.5 * length, upper_left_y)
Beispiel #4
0
def picture_wall2():
    wall1 = GPolygon()
    wall1.add_vertex((300, 0))
    wall1.add_vertex((350, 75))
    wall1.add_vertex((440, 100))
    wall1.add_vertex((410, 180))
    wall1.add_vertex((440, 220))
    wall1.add_vertex((460, 280))
    wall1.add_vertex((470, 340))
    wall1.add_vertex((463, 400))
    wall1.add_vertex((473, 430))
    wall1.add_vertex((453, 470))
    wall1.add_vertex((432, 520))
    wall1.add_vertex((420, 550))
    wall1.add_vertex((310, 635))
    wall1.add_vertex((335, 635))
    wall1.add_vertex((443, 550))
    wall1.add_vertex((455, 520))
    wall1.add_vertex((473, 470))
    wall1.add_vertex((495, 430))
    wall1.add_vertex((482, 400))
    wall1.add_vertex((492, 340))
    wall1.add_vertex((480, 280))
    wall1.add_vertex((464, 220))
    wall1.add_vertex((435, 180))
    wall1.add_vertex((450, 100))
    wall1.add_vertex((375, 75))
    wall1.add_vertex((300, 0))
    wall1.filled = True
    wall1.fill_color = 'gray'
    wall1.color = 'gray'
    return wall1
Beispiel #5
0
def sierpinski_triangle(order, length, upper_left_x, upper_left_y):
    """
	:param order: Level or sierpinski triangle
	:param length:  length of triangle
	:param upper_left_x:  the x start point of triangle
	:param upper_left_y:  the y start point of triangle
	:return: nothing
	"""
    if order == 0:  # base case
        pass
    else:
        tri = GPolygon()
        tri.add_vertex((upper_left_x, upper_left_y))
        tri.add_vertex((upper_left_x + length, upper_left_y))
        tri.add_vertex(
            (upper_left_x + length / 2, upper_left_y + length * 0.866))
        window.add(tri)

        sierpinski_triangle(order - 1, length / 2, upper_left_x,
                            upper_left_y)  # left top
        sierpinski_triangle(order - 1, length / 2, upper_left_x + length * 0.5,
                            upper_left_y)  # right top
        sierpinski_triangle(order - 1, length / 2,
                            upper_left_x + length * 0.25,
                            upper_left_y + length * 0.866 * 0.5)  # bottom
    pass
Beispiel #6
0
def sierpinski_triangle(order, length, upper_left_x, upper_left_y):
    """
	:param order:
	:param length:
	:param upper_left_x:
	:param upper_left_y:
	:return:
	"""
    if order == 0:
        return

    else:

        triangle = GPolygon()
        triangle.add_vertex((upper_left_x, upper_left_y))
        triangle.add_vertex((upper_left_x + length, upper_left_y))
        triangle.add_vertex(
            (upper_left_x + length / 2, upper_left_y + (length * 0.886)))
        triangle.filled = True
        triangle.fill_color = 'snow'

        window.add(triangle)

        sierpinski_triangle(order - 1, length / 2, upper_left_x, upper_left_y)

        sierpinski_triangle(order - 1, length / 2, upper_left_x + length / 2,
                            upper_left_y)

        sierpinski_triangle(order - 1, length / 2, upper_left_x + length / 4,
                            upper_left_y + (length * 0.886) / 2)
Beispiel #7
0
def tail():
    tail = GPolygon()
    tail.add_vertex((650, 450))
    tail.add_vertex((650, 500))
    tail.add_vertex((780, 430))
    tail.filled = True
    tail.fill_color = 'green'
    window.add(tail)
Beispiel #8
0
def eyebrow():
    brow = GPolygon()
    brow.add_vertex((540, 50))
    brow.add_vertex((600, 45))
    brow.add_vertex((600, 30))
    brow.filled = True
    brow.fill_color = 'black'
    window.add(brow)
Beispiel #9
0
def batman():
    #batman legs
    left_leg = GRect(40, 100, x = 280, y = 775)
    obj_fill_color_add(left_leg, "gray")
    left_shoe = GPolygon()
    polygon_helper(left_shoe, "dimgrey", (280, 840), (280, 880), (330, 880), (320, 840))
    right_leg = GRect(40, 100, x = 360, y = 775)
    obj_fill_color_add(right_leg, "gray")
    right_shoe = GPolygon()
    polygon_helper(right_shoe, "dimgrey", (360, 840), (360, 880), (410, 880), (400, 840))

    #batman head
    bat_ear1 = GPolygon()
    polygon_helper(bat_ear1, "gray", (275, 450), (325, 450), (300, 375))
    head = GOval(180, 220, x = 260, y = 400)
    obj_fill_color_add(head, "gray")
    bat_ear2 = GPolygon()
    polygon_helper(bat_ear2, "gray", (360, 450), (410, 450), (385, 375))

    #batman appearance
    face = GArc(275, 330, 0, -90, 300, 450)
    obj_fill_color_add(face, "bisque")
    eye = GRect(30, 10, x = 400, y = 475)
    obj_fill_color_add(eye, "white")
    mouth = GLine(405, 575, 425, 575)
    obj_fill_color_add(mouth, "black")

    #batman body
    left_arm = GPolygon()
    polygon_helper(left_arm, "gray", (275, 600), (210, 650), (275, 720), (300, 720), (250, 655), (340, 600))
    right_arm = GPolygon()
    polygon_helper(right_arm, "gray", (355, 600), (415, 650), (385, 720), (405, 720), (455, 650), (405, 600))
    cape = GPolygon()
    polygon_helper(cape, "dimgrey", (280, 580), (250, 800), (450, 800), (380, 580))
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)
Beispiel #11
0
def nobita_hand():
    hand = GPolygon()
    hand.add_vertex((200, 475))
    hand.add_vertex((310, 555))
    hand.add_vertex((310, 635))
    hand.add_vertex((200, 555))
    hand.filled = True
    hand.fill_color = 'antiquewhite'
    hand.color = 'antiquewhite'
    return hand
Beispiel #12
0
def nobita_handcloth():
    hand_cloth = GPolygon()
    hand_cloth.add_vertex((310, 555))
    hand_cloth.add_vertex((385, 505))
    hand_cloth.add_vertex((385, 585))
    hand_cloth.add_vertex((310, 635))
    hand_cloth.filled = True
    hand_cloth.fill_color = 'yellow'
    hand_cloth.color = 'yellow'
    return hand_cloth
Beispiel #13
0
def heart():
    my_heart = GPolygon()
    my_heart.add_vertex((280, 10))
    my_heart.add_vertex((230, 60))
    my_heart.add_vertex((330, 180))
    my_heart.add_vertex((430, 60))
    my_heart.add_vertex((380, 10))
    my_heart.add_vertex((330, 50))
    my_heart.filled = True
    my_heart.fill_color = 'light pink'
    window.add(my_heart)
Beispiel #14
0
def sierpinski_triangle(order, length, upper_left_x, upper_left_y):
	"""
											line1
											-----------
											 \       /
											  \     /
								line2		   \   /	line3
												\ /
	:param order: int, Controls the order of Sierpinski Triangle
	:param length: int, The length of order 1 Sierpinski Triangle
	:param upper_left_x: int, The upper left x coordinate of order 1 Sierpinski Triangle
	:param upper_left_y: int, The upper left y coordinate of order 1 Sierpinski Triangle
	:return:
	"""
	if order == 0:
		pass
	else:
		# line1 = GLine(upper_left_x, upper_left_y, upper_left_x + length, upper_left_y)
		# line2 = GLine(upper_left_x, upper_left_y, upper_left_x + 0.5*length, upper_left_y + (3**0.5)/2*length)
		# line3 = GLine(upper_left_x + length, upper_left_y, upper_left_x + 0.5*length, upper_left_y + (3**0.5)/2*length)
		# window.add(line1)
		# window.add(line2)
		# window.add(line3)

		# if you want to draw the triangle, you can use it
		# ----------------------------------------------------------------
		triangle = GPolygon()
		triangle.add_vertex((upper_left_x, upper_left_y))
		triangle.add_vertex((upper_left_x + length, upper_left_y))
		triangle.add_vertex((upper_left_x + 0.5*length, upper_left_y + (3**0.5)/2*length))
		# draw it from the line!
		# e.g.
		triangle.filled = True
		if order % 3 == 0:
			triangle.fill_color = 'blue'
		elif order % 3 == 1:
			triangle.fill_color = 'magenta'
		else:
			triangle.fill_color = 'pink'

		window.add(triangle)
		# ----------------------------------------------------------------


		# make the upper left triangle
		sierpinski_triangle(order-1, length/2, upper_left_x, upper_left_y)

		# make the upper right triangle
		sierpinski_triangle(order-1, length/2, upper_left_x + length/2, upper_left_y)

		# make the lower triangle
		sierpinski_triangle(order-1, length/2, upper_left_x + 0.25*length, upper_left_y + (3**0.5)/2*(length/2))
Beispiel #15
0
def back():
    back0 = GPolygon()
    back0.add_vertex((650, 230))
    back0.add_vertex((650, 280))
    back0.add_vertex((700, 255))
    back0.filled = True
    back0.fill_color = 'white'
    window.add(back0)
    back1 = GPolygon()
    back1.add_vertex((650, 280))
    back1.add_vertex((650, 330))
    back1.add_vertex((700, 305))
    back1.filled = True
    back1.fill_color = 'white'
    window.add(back1)
    back2 = GPolygon()
    back2.add_vertex((650, 330))
    back2.add_vertex((650, 380))
    back2.add_vertex((700, 355))
    back2.filled = True
    back2.fill_color = 'white'
    window.add(back2)
Beispiel #16
0
def hand_finger():
    fin0 = GPolygon()
    fin0.add_vertex((420, 300))
    fin0.add_vertex((450, 300))
    fin0.add_vertex((450, 325))
    fin0.filled = True
    fin0.fill_color = 'ivory'
    window.add(fin0)
    fin1 = GPolygon()
    fin1.add_vertex((420, 325))
    fin1.add_vertex((450, 325))
    fin1.add_vertex((450, 350))
    fin1.filled = True
    fin1.fill_color = 'ivory'
    window.add(fin1)
    fin2 = GPolygon()
    fin2.add_vertex((420, 350))
    fin2.add_vertex((450, 350))
    fin2.add_vertex((450, 375))
    fin2.filled = True
    fin2.fill_color = 'ivory'
    window.add(fin2)
Beispiel #17
0
def draw_triangle(length, start_x, start_y):
    """
	功能:
	:param length:
	:param start_x:
	:param start_y:
	:return:
	"""
    triangle = GPolygon()
    triangle.add_vertex((start_x, start_y))
    for edge in range(3):
        triangle.add_polar_edge(length, -120 * edge)
    window.add(triangle)
Beispiel #18
0
def make_polygon(num, coordinate, color):
    """
    Draw a polygon
    :param num: int, number of vertex
    :param coordinate: list, coordinate of every vertex :[(x1, y1), (x2, y2)...]
    :param color: str, the color want to fill inside
    """
    polygon = GPolygon()
    for i in range(num):
        x = coordinate[i][0] * SIZE
        y = coordinate[i][1] * SIZE
        polygon.add_vertex((x, y))
    window.add(polygon)
    polygon.filled = True
    polygon.fill_color = color
Beispiel #19
0
def myGArc(width, height, start_ang, sweep_ang, x=0, y=0):
    rx, ry = width / 2, height / 2
    cx, cy = x + rx, y + ry

    angs = np.linspace(start_ang, sweep_ang, 10000)
    arc = GPolygon()
    for ang in angs:
        arc_x = cx + rx * np.cos(np.deg2rad(ang))
        arc_y = cy - ry * np.sin(np.deg2rad(ang))
        arc.add_vertex((arc_x, arc_y))
        #print(ang)
    # end_x = cx + rx*np.cos(np.deg2rad(start_ang+sweep_ang))
    # end_y = cy - ry*np.sin(np.deg2rad(start_ang+sweep_ang))

    return arc
Beispiel #20
0
    def link_point(self, point):
        """
        link the point of pose list and make GObject.
        :param point: Every piece of bird is consist of GPolygon shape, which is make up by these points.
        """
        r = [random.randint(225, 255), random.randint(240, 255), random.randint(255, 255)]
        shape = GPolygon()
        shape.color = 'lightgray'
        shape.filled = True
        shape.fill_color = (r[0], r[1], r[2])
        for j in range(len(point)):
            shape.add_vertex(point[j])
        window.add(shape)
        self.shape_box.append(shape)

        self.eye.filled = True
        self.eye.fill_color = 'navy'
        window.add(self.eye, 370, 210)
Beispiel #21
0
def picture_wall():
    wall1 = GPolygon()
    wall1.add_vertex((0, 0))
    wall1.add_vertex((300, 0))
    wall1.add_vertex((250, 75))
    wall1.add_vertex((180, 100))
    wall1.add_vertex((160, 180))
    wall1.add_vertex((170, 220))
    wall1.add_vertex((140, 280))
    wall1.add_vertex((230, 340))
    wall1.add_vertex((220, 400))
    wall1.add_vertex((200, 440))
    wall1.add_vertex((200, 500))
    wall1.add_vertex((220, 550))
    wall1.add_vertex((310, 635))
    wall1.add_vertex((300, 900))
    wall1.add_vertex((0, 900))
    wall1.filled = True
    wall1.fill_color = 'darkgrey'
    wall1.color = 'grey'
    return wall1
Beispiel #22
0
def rescue_light():
    #color database
    light_color = ["dimgrey", "lightgrey", "gainsboro", "whitesmoke"]

    light_beam = GPolygon()
    light_beam.color = "darkgrey"
    polygon_helper(light_beam, "darkgrey", (920, 350), (1300, 650), (1255, 250))
    bat_icon_background = GOval(385, 300, x = 870, y = 100)
    bat_icon_background.color = "darkgrey"
    obj_fill_color_add(bat_icon_background, "darkgrey")
    # gradually brighten the beam
    pause(1000)
    for s in light_color:
        light_beam.color = s
        light_beam.fill_color = s
        bat_icon_background.color = s
        bat_icon_background.fill_color = s
        pause(800)
    #batman icon in light
    bat_icon = GImage("batman.jpeg")
    window.add(bat_icon, bat_icon_background.x + 60, bat_icon_background.y + 45)
Beispiel #23
0
def picture_wall1():
    wall1 = GPolygon()
    wall1.add_vertex((600, 0))
    wall1.add_vertex((300, 0))
    wall1.add_vertex((350, 75))
    wall1.add_vertex((440, 100))
    wall1.add_vertex((410, 180))
    wall1.add_vertex((440, 220))
    wall1.add_vertex((460, 280))
    wall1.add_vertex((470, 340))
    wall1.add_vertex((463, 400))
    wall1.add_vertex((473, 430))
    wall1.add_vertex((453, 470))
    wall1.add_vertex((432, 520))
    wall1.add_vertex((420, 550))
    wall1.add_vertex((310, 635))
    wall1.add_vertex((300, 900))
    wall1.add_vertex((600, 900))
    wall1.filled = True
    wall1.fill_color = 'darkgrey'
    wall1.color = 'darkgrey'
    return wall1
def sierpinski_triangle(order, length, upper_left_x, upper_left_y):
	"""
	:param order:Controls the order of Sierpinski Triangle
	:param length:The length of order 1 Sierpinski Triangle
	:param upper_left_x:The upper left x coordinate of order 1 Sierpinski Triangle
	:param upper_left_y:The upper left y coordinate of order 1 Sierpinski Triangle
	:return:
	"""
	if order == 0:
		pass
	else:
		triangle = GPolygon()
		triangle.add_vertex((upper_left_x, upper_left_y))
		triangle.add_vertex((upper_left_x+length, upper_left_y))
		triangle.add_vertex((upper_left_x + length / 2, upper_left_y + length * 0.866))
		window.add(triangle)
		# upper-left
		sierpinski_triangle(order-1, length/2, upper_left_x, upper_left_y)

		# upper-right
		sierpinski_triangle(order-1, length/2, upper_left_x+length/2, upper_left_y)

		# lower-mid
		sierpinski_triangle(order-1, length/2, upper_left_x+length/4, upper_left_y+(length/2)*0.866)
Beispiel #25
0
    def speak(self):
        """
        This method give one triangle, four round corner and five rectangle to present talk bar,
        self.words will be the content of speak.
        """
        label = GLabel(self.words, 435, 170)
        label.font = 'Verdana-20'

        triangle = GPolygon()
        triangle.add_vertex((label.x+10, label.y))
        triangle.add_vertex((label.x+30, label.y))
        triangle.add_vertex((label.x, label.y+30))

        rect = GRect(label.width, label.height, x=label.x, y=label.y - label.height)
        rect_top = GRect(rect.width, 10, x=rect.x, y=rect.y - 10)
        rect_left = GRect(10, rect.height, x=rect.x - 10, y=rect.y)
        rect_button = GRect(rect.width, 10, x=rect.x, y=rect.y + rect.height)
        rect_right = GRect(10, rect.height, x=rect.x + rect.width, y=rect.y)

        arc_right_top = GArc(40, 40, 0, 90, rect.x - 10 + rect.width, rect.y - 10)
        arc_left_top = GArc(40, 40, 90, 90, rect.x - 10, rect.y - 10)
        arc_left_button = GArc(40, 40, 180, 90, rect.x - 10, rect.y - 10 + rect.height)
        arc_right_button = GArc(40, 40, 270, 90, rect.x - 10 + rect.width, rect.y - 10 + rect.height)

        self.talk_block = [triangle, rect, rect_top, rect_left, rect_button, rect_right, arc_right_top, arc_left_top,
                           arc_left_button,
                           arc_right_button, label]

        for i in self.talk_block:
            i.filled = True
            i.fill_color = 'crimson'
            i.color = 'crimson'
            if i == self.talk_block[-1]:
                i.color = 'azure'
            window.add(i)
        print(label.width, label.height)
Beispiel #26
0
def teeth():
    tooth1 = GPolygon()
    tooth1.add_vertex((450, 170))
    tooth1.add_vertex((480, 170))
    tooth1.add_vertex((465, 190))
    tooth1.filled = True
    tooth1.fill_color = 'white'
    window.add(tooth1)
    tooth2 = GPolygon()
    tooth2.add_vertex((480, 170))
    tooth2.add_vertex((510, 170))
    tooth2.add_vertex((495, 190))
    tooth2.filled = True
    tooth2.fill_color = 'white'
    window.add(tooth2)
    tooth3 = GPolygon()
    tooth3.add_vertex((510, 170))
    tooth3.add_vertex((540, 170))
    tooth3.add_vertex((525, 190))
    tooth3.filled = True
    tooth3.fill_color = 'white'
    window.add(tooth3)
    tooth4 = GPolygon()
    tooth4.add_vertex((450, 230))
    tooth4.add_vertex((480, 230))
    tooth4.add_vertex((465, 210))
    tooth4.filled = True
    tooth4.fill_color = 'white'
    window.add(tooth4)
    tooth5 = GPolygon()
    tooth5.add_vertex((480, 230))
    tooth5.add_vertex((510, 230))
    tooth5.add_vertex((495, 210))
    tooth5.filled = True
    tooth5.fill_color = 'white'
    window.add(tooth5)
    tooth6 = GPolygon()
    tooth6.add_vertex((510, 230))
    tooth6.add_vertex((540, 230))
    tooth6.add_vertex((525, 210))
    tooth6.filled = True
    tooth6.fill_color = 'white'
    window.add(tooth6)
Beispiel #27
0
def main():
    """
    TODO:
    """
    window = GWindow(width=1200, height=600)
    body = GRect(200, 300, x=200, y=150)
    head = GOval(200, 200, x=200, y=50)
    eye = GOval(170, 120, x=250, y=130)
    left_foot = GRect(80, 100, x=200, y=450)
    right_foot = GRect(80, 100, x=320, y=450)
    back = GPolygon()
    back.add_vertex((200, 200))
    back.add_vertex((130, 220))
    back.add_vertex((130, 400))
    back.add_vertex((200, 400))
    handle_1 = GRect(40, 100, x=500, y=250)
    handle_2 = GRect(80, 40, x=420, y=280)
    knife = GPolygon()
    knife.add_vertex((540, 280))
    knife.add_vertex((570, 260))
    knife.add_vertex((590, 275))
    knife.add_vertex((610, 265))
    knife.add_vertex((640, 315))
    knife.add_vertex((540, 315))

    head.filled = True
    body.filled = True
    eye.filled = True
    back.filled = True
    handle_1.filled = True
    left_foot.filled = True
    right_foot.filled = True
    handle_2.filled = True
    knife.filled = True

    head.fill_color = 'red'
    body.fill_color = 'red'
    eye.fill_color = 'skyblue'
    left_foot.fill_color = 'red'
    right_foot.fill_color = 'red'
    back.fill_color = 'red'
    handle_1.fill_color = 'black'
    handle_2.fill_color = 'black'
    knife.fill_color = 'grey'

    head.color = 'red'
    body.color = 'red'
    left_foot.color = 'red'
    right_foot.color = 'red'

    window.add(body)
    window.add(head)
    window.add(eye)
    window.add(left_foot)
    window.add(right_foot)
    window.add(back)
    window.add(handle_1)
    window.add(handle_2)
    window.add(knife)

    body2 = GRect(200, 300, x=750, y=150)
    head2 = GOval(200, 200, x=750, y=50)
    eye2 = GOval(170, 120, x=730, y=130)
    left_foot2 = GRect(80, 100, x=750, y=450)
    right_foot2 = GRect(80, 100, x=870, y=450)
    back2 = GPolygon()
    back2.add_vertex((950, 200))
    back2.add_vertex((1020, 220))
    back2.add_vertex((1020, 400))
    back2.add_vertex((950, 400))

    knife2 = GPolygon()
    knife2.add_vertex((700, 200))
    knife2.add_vertex((680, 180))
    knife2.add_vertex((650, 200))
    knife2.add_vertex((650, 400))
    knife2.add_vertex((700, 400))

    head2.filled = True
    body2.filled = True
    eye2.filled = True
    back2.filled = True
    left_foot2.filled = True
    right_foot2.filled = True

    knife2.filled = True

    head2.fill_color = 'purple'
    body2.fill_color = 'purple'
    eye2.fill_color = 'skyblue'
    left_foot2.fill_color = 'purple'
    right_foot2.fill_color = 'purple'
    back2.fill_color = 'purple'
    knife2.fill_color = 'brown'

    head2.color = 'purple'
    body2.color = 'purple'
    left_foot2.color = 'purple'
    right_foot2.color = 'purple'
    knife2.color = 'brown'

    window.add(body2)
    window.add(head2)
    window.add(eye2)
    window.add(left_foot2)
    window.add(right_foot2)
    window.add(back2)

    label = GLabel('Among Us', x=450, y=500)
    label.font = 'Courier-50-italic'
    window.add(label)

    window.add(knife2)
Beispiel #28
0
def main():
    """
    TODO:
    This figure uses campy module to demonstrate personality.
    A lot of faiths hold by people, just like the shape of circles or triangles,
    while eventually others can only see the polygon.
    """
    window=GWindow(600,600)

    # color of background
    rect=GRect(800,800)
    rect.filled=True
    rect.fill_color='lightgrey'
    window.add(rect)

    # polygon, circle ,rect and triangle with different colors
    polygon1=GPolygon()
    polygon1.add_vertex((550, 590))
    polygon1.add_vertex((570, 360))
    polygon1.add_vertex((100, 60))
    polygon1.filled=True
    polygon1.fill_color='greenyellow'
    window.add(polygon1)

    rect1=GRect(335,335,x=135,y=150)
    rect1.filled=True
    rect1.fill_color='sage'
    rect2=GRect(370,370,x=120,y=135)
    rect2.filled=True
    rect2.fill_color='magenta'
    rect3=GRect(400,400,x=105,y=120)
    rect3.filled=True
    rect3.fill_color='purple'
    rect4=GRect(440,440,x=85,y=100)
    rect4.filled=True
    rect4.fill_color='peachpuff'
    window.add(rect4)
    window.add(rect3)
    window.add(rect2)
    window.add(rect1)

    circle5=GOval(265,265,x=170,y=185)
    circle5.filled=True
    circle5.fill_color='lightsage'
    circle6=GOval(285,285,x=160,y=175)
    circle6.filled=True
    circle6.fill_color='tan'
    circle7=GOval(305,305,x=150,y=165)
    circle7.filled=True
    circle7.fill_color='midnightblue'
    circle8=GOval(325,325,x=140,y=155)
    circle8.filled=True
    circle8.fill_color='powderblue'
    window.add(circle8)
    window.add(circle7)
    window.add(circle6)
    window.add(circle5)

    triangle1=GPolygon()
    triangle1.add_vertex((300,230))
    triangle1.add_vertex((225,340))
    triangle1.add_vertex((375,340))
    triangle2=GPolygon()
    triangle2.add_vertex((300,215))
    triangle2.add_vertex((210,350))
    triangle2.add_vertex((390,350))
    triangle1.filled=True
    triangle1.fill_color='pink'
    triangle2.filled=True
    triangle2.fill_color='lightgrey'
    triangle3=GPolygon()
    triangle3.add_vertex((300,200))
    triangle3.add_vertex((195,360))
    triangle3.add_vertex((405,360))
    triangle4=GPolygon()
    triangle4.add_vertex((300,185))
    triangle4.add_vertex((180,370))
    triangle4.add_vertex((420,370))
    triangle3.filled=True
    triangle3.fill_color='linen'
    triangle4.filled=True
    triangle4.fill_color='yellow'
    window.add(triangle4)
    window.add(triangle3)
    window.add(triangle2)
    window.add(triangle1)

    circle1=GOval(20,20,x=290,y=290)
    circle1.filled=True
    circle1.fill_color='aquamarine'
    circle2=GOval(40,40,x=280,y=280)
    circle2.filled=True
    circle2.fill_color='aqua'
    circle3=GOval(60,60,x=270,y=270)
    circle3.filled=True
    circle3.fill_color='darkblue'
    circle4=GOval(80,80,x=260,y=260)
    circle4.filled=True
    circle4.fill_color='blueviolet'
    window.add(circle4)
    window.add(circle3)
    window.add(circle2)
    window.add(circle1)

    polygon=GPolygon()
    polygon.add_vertex((100, 60))
    polygon.add_vertex((50,100))
    polygon.add_vertex((40,180))
    polygon.add_vertex((20,400))
    polygon.add_vertex((30,550))
    polygon.add_vertex((180,580))
    polygon.add_vertex((400, 550))
    polygon.add_vertex((550, 590))
    polygon.filled=True
    polygon.fill_color='salmon'
    window.add(polygon)

    # logo
    sc101=GLabel('SC101-2020.Nov')
    sc101.font='Courier-15-bold-italic'
    window.add(sc101,0,window.height-sc101.height+20)
Beispiel #29
0
def main():
    """
    Create a window and lots of objects from GObject.
    Add those objects to the window to make the drawing.
    """

    window = GWindow(width=600, height=470, title='little my')

    r = GRect(600, 470, x=0, y=0)
    r.filled = True
    r.color = '#1C3747'
    r.fill_color = '#1C3747'
    window.add(r)

    wood1 = GRect(25, 300, x=360, y=170)
    wood1.filled = True
    wood1.color = '#C29950'
    wood1.fill_color = '#C29950'
    window.add(wood1)

    wood3 = GRect(280, 190, x=230, y=10)
    wood3.filled = True
    wood3.color = '#8F4629'
    wood3.fill_color = '#8F4629'
    window.add(wood3)

    wood2 = GRect(240, 150, x=250, y=30)
    wood2.filled = True
    wood2.color = '#C29950'
    wood2.fill_color = '#C29950'
    window.add(wood2)

    grass = GOval(50, 140, x=-10, y=400)
    grass.filled = True
    grass.color = '#405F3E'
    grass.fill_color = '#405F3E'
    window.add(grass)

    grass = GOval(60, 140, x=10, y=420)
    grass.filled = True
    grass.color = '#5D7160'
    grass.fill_color = '#5D7160'
    window.add(grass)

    grass = GOval(90, 160, x=40, y=420)
    grass.filled = True
    grass.color = '#61806B'
    grass.fill_color = '#61806B'
    window.add(grass)

    grass = GOval(100, 140, x=80, y=430)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#435646'
    window.add(grass)

    grass = GOval(180, 100, x=90, y=430)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#435646'
    window.add(grass)

    grass = GOval(100, 150, x=200, y=410)
    grass.filled = True
    grass.color = '#405F3E'
    grass.fill_color = '#405F3E'
    window.add(grass)

    grass = GOval(110, 180, x=230, y=420)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#435646'
    window.add(grass)

    l_shoe = GPolygon()
    l_shoe.add_vertex((170, 370))
    l_shoe.add_vertex((190, 445))
    l_shoe.add_vertex((190, 445))
    l_shoe.add_vertex((200, 445))
    l_shoe.add_vertex((210, 445))
    l_shoe.add_vertex((220, 440))
    l_shoe.add_vertex((230, 455))
    l_shoe.add_vertex((220, 465))
    l_shoe.add_vertex((200, 465))
    l_shoe.add_vertex((185, 460))
    l_shoe.add_vertex((180, 465))
    l_shoe.add_vertex((168, 465))
    l_shoe.add_vertex((155, 370))
    l_shoe.filled = True
    l_shoe.fill_color = 'black'
    window.add(l_shoe)

    r_shoe = GPolygon()
    r_shoe.add_vertex((130, 370))
    r_shoe.add_vertex((110, 445))
    r_shoe.add_vertex((110, 445))
    r_shoe.add_vertex((100, 445))
    r_shoe.add_vertex((90, 445))
    r_shoe.add_vertex((80, 440))
    r_shoe.add_vertex((70, 455))
    r_shoe.add_vertex((85, 465))
    r_shoe.add_vertex((100, 465))
    r_shoe.add_vertex((115, 460))
    r_shoe.add_vertex((120, 465))
    r_shoe.add_vertex((132, 465))
    r_shoe.add_vertex((145, 370))
    r_shoe.filled = True
    r_shoe.fill_color = 'black'
    window.add(r_shoe)

    dress = GPolygon()
    dress.add_vertex((108, 218))
    dress.add_vertex((96, 250))
    dress.add_vertex((45, 260))
    dress.add_vertex((43, 275))
    dress.add_vertex((71, 330))
    dress.add_vertex((30, 390))
    dress.add_vertex((90, 410))
    dress.add_vertex((135, 415))
    dress.add_vertex((166, 420))
    dress.add_vertex((200, 415))
    dress.add_vertex((270, 390))
    dress.add_vertex((205, 265))
    dress.add_vertex((355, 265))
    dress.add_vertex((355, 250))
    dress.add_vertex((205, 250))
    dress.add_vertex((193, 218))
    dress.filled = True
    dress.fill_color = '#B5272D'
    window.add(dress)

    l_hand = GPolygon()
    l_hand.add_vertex((90, 268))
    l_hand.add_vertex((60, 275))
    l_hand.add_vertex((80, 310))
    l_hand.filled = True
    l_hand.fill_color = '#1C3747'
    window.add(l_hand)

    l_tie = GPolygon()
    l_tie.add_vertex((150, 238))
    l_tie.add_vertex((105, 220))
    l_tie.add_vertex((105, 255))
    l_tie.filled = True
    l_tie.fill_color = '#D17989'
    window.add(l_tie)

    r_tie = GPolygon()
    r_tie.add_vertex((150, 238))
    r_tie.add_vertex((195, 220))
    r_tie.add_vertex((195, 255))
    r_tie.filled = True
    r_tie.fill_color = '#D17989'
    window.add(r_tie)

    tie = GOval(20, 26, x=140, y=225)
    tie.filled = True
    tie.fill_color = '#D17989'
    window.add(tie)

    l_ear = GOval(40, 40, x=60, y=150)
    l_ear.filled = True
    l_ear.fill_color = '#FFF1E2'
    window.add(l_ear)

    r_ear = GOval(40, 40, x=200, y=150)
    r_ear.filled = True
    r_ear.fill_color = '#FFF1E2'
    window.add(r_ear)

    face = GOval(160, 140, x=70, y=90)
    face.filled = True
    face.fill_color = '#FFF1E2'
    window.add(face)

    l_eye = GArc(40, 90, -10, -180, x=90, y=140)
    l_eye.filled = True
    l_eye.fill_color = 'white'
    window.add(l_eye)

    l_eye_b = GArc(20, 60, -10, -178, x=100, y=148)
    l_eye_b.filled = True
    l_eye_b.fill_color = '#4A8165'
    window.add(l_eye_b)

    r_eye = GArc(40, 90, 10, -180, x=170, y=140)
    r_eye.filled = True
    r_eye.fill_color = 'white'
    window.add(r_eye)

    r_eye_b = GArc(20, 60, 10, -178, x=180, y=148)
    r_eye_b.filled = True
    r_eye_b.fill_color = '#4A8165'
    window.add(r_eye_b)

    nose1 = GLine(146, 160, 148, 173)
    nose1.color = 'black'
    window.add(nose1)

    nose2 = GLine(156, 160, 154, 173)
    nose2.color = 'black'
    window.add(nose2)

    nose3 = GLine(149, 175, 140, 199)
    nose3.color = 'black'
    window.add(nose3)

    nose4 = GLine(162, 199, 153, 175)
    nose4.color = 'black'
    window.add(nose4)

    nose5 = GLine(140, 199, 162, 199)
    nose5.color = 'black'
    window.add(nose5)

    mouth = GArc(100, 80, -30, -120, x=110, y=190)
    mouth.color = 'black'
    window.add(mouth)

    h_tail1 = GOval(50, 100, x=125, y=30)
    h_tail1.filled = True
    h_tail1.fill_color = '#F39401'
    h_tail1.color = '#F39401'
    window.add(h_tail1)

    h_tail1_line1 = GArc(160, 110, 120, 100, x=135, y=30)
    h_tail1_line1.color = 'black'
    window.add(h_tail1_line1)

    h_tail1_line2 = GArc(160, 110, 120, 100, x=142, y=30)
    h_tail1_line2.color = 'black'
    window.add(h_tail1_line2)

    h_tail1_line3 = GArc(160, 110, 60, -100, x=120, y=30)
    h_tail1_line3.color = 'black'
    window.add(h_tail1_line3)

    h_tail1_line4 = GArc(160, 110, 60, -100, x=127, y=30)
    h_tail1_line4.color = 'black'
    window.add(h_tail1_line4)

    h_tail1_line5 = GLine(150, 50, 150, 86)
    h_tail1_line5.color = 'black'
    window.add(h_tail1_line5)

    hair = GArc(160, 240, 0, 180, x=70, y=90)
    hair.filled = True
    hair.fill_color = '#F39401'
    hair.color = '#F39401'
    window.add(hair)

    hairline1 = GArc(800, 230, 115, 69, x=80, y=90)
    hairline1.color = 'black'
    window.add(hairline1)

    hairline2 = GArc(820, 230, 120, 66, x=95, y=89)
    hairline2.fill = 'black'
    window.add(hairline2)

    hairline3 = GArc(840, 240, 130, 58, x=110, y=88)
    hairline3.fill = 'black'
    window.add(hairline3)

    hairline4 = GArc(860, 240, 135, 56, x=125, y=87)
    hairline4.fill = 'black'
    window.add(hairline4)

    hairline5 = GArc(920, 250, 140, 53, x=135, y=85)
    hairline5.fill = 'black'
    window.add(hairline5)

    hairline6 = GLine(150, 110, 153, 150)
    hairline6.fill = 'black'
    window.add(hairline6)

    hairline7 = GArc(300, 400, 90, -75, x=80, y=96)
    hairline7.fill = 'black'
    window.add(hairline7)

    hairline8 = GArc(300, 425, 85, -70, x=75, y=93)
    hairline8.fill = 'black'
    window.add(hairline8)

    hairline9 = GArc(320, 475, 70, -55, x=90, y=90)
    hairline9.fill = 'black'
    window.add(hairline9)

    hairline10 = GArc(280, 500, 65, -50, x=100, y=90)
    hairline10.fill = 'black'
    window.add(hairline10)

    hairline11 = GArc(280, 530, 60, -45, x=100, y=90)
    hairline11.fill = 'black'
    window.add(hairline11)

    l_hand = GArc(50, 50, 40, -180, x=43, y=298)
    l_hand.filled = True
    l_hand.fill_color = 'black'
    window.add(l_hand)

    r_hand = GOval(40, 40, x=350, y=235)
    r_hand.filled = True
    r_hand.fill_color = 'black'
    window.add(r_hand)

    label = GLabel('Python!', x=263, y=140)
    label.font = 'Verdana-38-italic-bold'
    label.color = 'white'
    window.add(label)

    grass = GOval(120, 180, x=260, y=430)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#5D7160'
    window.add(grass)

    grass = GOval(120, 180, x=330, y=450)
    grass.filled = True
    grass.color = '#405F3E'
    grass.fill_color = '#405F3E'
    window.add(grass)

    grass = GOval(120, 180, x=370, y=430)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#435646'
    window.add(grass)

    grass = GOval(120, 150, x=430, y=420)
    grass.filled = True
    grass.color = '#4F5939'
    grass.fill_color = '#4F5939'
    window.add(grass)

    grass = GOval(80, 180, x=470, y=410)
    grass.filled = True
    grass.color = '#405F3E'
    grass.fill_color = '#405F3E'
    window.add(grass)

    grass = GOval(120, 150, x=500, y=440)
    grass.filled = True
    grass.color = '#435646'
    grass.fill_color = '#435646'
    window.add(grass)

    hatti = GRect(50, 170, x=420, y=300)
    hatti.filled = True
    hatti.color = '#DADADA'
    hatti.fill_color = '#DADADA'
    window.add(hatti)

    hatti_h = GOval(50, 50, x=420, y=275)
    hatti_h.filled = True
    hatti_h.color = '#DADADA'
    hatti_h.fill_color = '#DADADA'
    window.add(hatti_h)

    hatti_e = GOval(25, 25, x=420, y=300)
    hatti_e.filled = True
    hatti_e.color = 'black'
    hatti_e.fill_color = 'white'
    window.add(hatti_e)

    hatti_ee = GOval(25, 25, x=445, y=300)
    hatti_ee.filled = True
    hatti_ee.color = 'black'
    hatti_ee.fill_color = 'white'
    window.add(hatti_ee)

    hatti_b = GOval(10, 10, x=452.5, y=307.5)
    hatti_b.filled = True
    hatti_b.color = 'black'
    hatti_b.fill_color = 'black'
    window.add(hatti_b)

    hatti_bb = GOval(10, 10, x=427.5, y=307.5)
    hatti_bb.filled = True
    hatti_bb.color = 'black'
    hatti_bb.fill_color = 'black'
    window.add(hatti_bb)

    hatti = GRect(50, 210, x=480, y=260)
    hatti.filled = True
    hatti.color = '#DADADA'
    hatti.fill_color = '#DADADA'
    window.add(hatti)

    hatti_h = GOval(50, 50, x=480, y=235)
    hatti_h.filled = True
    hatti_h.color = '#DADADA'
    hatti_h.fill_color = '#DADADA'
    window.add(hatti_h)

    hatti_e = GOval(25, 25, x=480, y=260)
    hatti_e.filled = True
    hatti_e.color = 'black'
    hatti_e.fill_color = 'white'
    window.add(hatti_e)

    hatti_ee = GOval(25, 25, x=505, y=260)
    hatti_ee.filled = True
    hatti_ee.color = 'black'
    hatti_ee.fill_color = 'white'
    window.add(hatti_ee)

    hatti_b = GOval(10, 10, x=512.5, y=267.5)
    hatti_b.filled = True
    hatti_b.color = 'black'
    hatti_b.fill_color = 'black'
    window.add(hatti_b)

    hatti_bb = GOval(10, 10, x=487.5, y=267.5)
    hatti_bb.filled = True
    hatti_bb.color = 'black'
    hatti_bb.fill_color = 'black'
    window.add(hatti_bb)

    hatti = GRect(50, 150, x=520, y=320)
    hatti.filled = True
    hatti.fill_color = '#DADADA'
    window.add(hatti)

    hatti_h = GOval(50, 50, x=520, y=295)
    hatti_h.filled = True
    hatti_h.fill_color = '#DADADA'
    window.add(hatti_h)

    r = GRect(48, 25, x=521, y=321)
    r.filled = True
    r.color = '#DADADA'
    r.fill_color = '#DADADA'
    window.add(r)

    hatti_e = GOval(25, 25, x=520, y=320)
    hatti_e.filled = True
    hatti_e.color = 'black'
    hatti_e.fill_color = 'white'
    window.add(hatti_e)

    hatti_ee = GOval(25, 25, x=545, y=320)
    hatti_ee.filled = True
    hatti_ee.color = 'black'
    hatti_ee.fill_color = 'white'
    window.add(hatti_ee)

    hatti_b = GOval(10, 10, x=552.5, y=327.5)
    hatti_b.filled = True
    hatti_b.color = 'black'
    hatti_b.fill_color = 'black'
    window.add(hatti_b)

    hatti_bb = GOval(10, 10, x=527.5, y=327.5)
    hatti_bb.filled = True
    hatti_bb.color = 'black'
    hatti_bb.fill_color = 'black'
    window.add(hatti_bb)

    hatti = GRect(50, 150, x=450, y=380)
    hatti.filled = True
    hatti.fill_color = '#DADADA'
    window.add(hatti)

    hatti_h = GOval(50, 50, x=450, y=355)
    hatti_h.filled = True
    hatti_h.fill_color = '#DADADA'
    window.add(hatti_h)

    r = GRect(48, 25, x=451, y=380)
    r.filled = True
    r.color = '#DADADA'
    r.fill_color = '#DADADA'
    window.add(r)

    hatti_e = GOval(25, 25, x=450, y=380)
    hatti_e.filled = True
    hatti_e.color = 'black'
    hatti_e.fill_color = 'white'
    window.add(hatti_e)

    hatti_ee = GOval(25, 25, x=475, y=380)
    hatti_ee.filled = True
    hatti_ee.color = 'black'
    hatti_ee.fill_color = 'white'
    window.add(hatti_ee)

    hatti_b = GOval(10, 10, x=457.5, y=387.5)
    hatti_b.filled = True
    hatti_b.color = 'black'
    hatti_b.fill_color = 'black'
    window.add(hatti_b)

    hatti_bb = GOval(10, 10, x=482.5, y=387.5)
    hatti_bb.filled = True
    hatti_bb.color = 'black'
    hatti_bb.fill_color = 'black'
    window.add(hatti_bb)
Beispiel #30
0
def night_view():
    # total 12 buildings
    building = [None] * 12

    #total 10 windows
    windows_position = [[350, 550], [525, 450], [525, 550], [650, 650], [725, 500], [850, 400], [850, 450], [950, 600],
                        [1350, 600], [1450, 500]]
    building_window = [None] * len(windows_position)

    # start creating buildings in night view
    building[0] = GPolygon()
    polygon_helper(building[0], "black", (300, 500), (300, 750), (400, 750), (400, 500))
    building[1] = GPolygon()
    polygon_helper(building[1], "black", (400, 600), (400, 750), (500, 750), (500, 400))
    building[2] = GPolygon()
    polygon_helper(building[2], "black", (500, 400), (400, 750), (600, 750), (600, 400))
    building[3] = GPolygon()
    polygon_helper(building[3], "black", (600, 600), (400, 750), (700, 750), (700, 600))
    building[4] = GPolygon()
    polygon_helper(building[4], "black", (700, 450), (700, 750), (800, 750), (800, 450))
    building[5] = GPolygon()
    polygon_helper(building[5], "black", (800, 350), (800, 750), (900, 750), (900, 350), (850, 300))
    building[6] = GPolygon()
    polygon_helper(building[6], "black", (900, 550), (900, 750), (1000, 750), (1000, 550))
    building[7] = GPolygon()
    polygon_helper(building[7], "black", (1000, 600), (1000, 750), (1100, 750), (1100, 600))
    building[8] = GPolygon()
    polygon_helper(building[8], "black", (1100, 650), (1100, 750), (1200, 750), (1200, 650))
    building[9] = GPolygon()
    polygon_helper(building[9], "black", (1200, 600), (1200, 750), (1300, 750), (1300, 650))
    building[10] = GPolygon()
    polygon_helper(building[10], "black", (1300, 525), (1300, 750), (1400, 750), (1400, 525))
    building[11] = GPolygon()
    polygon_helper(building[11], "black", (1400, 450), (1400, 750), (1500, 750), (1500, 450))

    #start creating windows in night view
    for i in range(len(windows_position)):
        building_window[i] = GRect(20, 20, x = windows_position[i][0], y = windows_position[i][1])
        obj_fill_color_add(building_window[i], "silver")