Beispiel #1
0
def couldsOval(position_x,position_y):
    """
    The following code print out some cloud
    """
    for i in range(position_x,window.width,100):
        clouds = GOval(50,30,x=i,y=position_y+10)
        window.add(clouds)
        clouds.filled = True
        clouds.color = "Blue"
        clouds.fill_color = "Blue"
    for j in range(position_x+25,window.width,100):
        clouds = GOval(40,30,x=j,y=position_y)
        window.add(clouds)
        clouds.filled = True
        clouds.color = "Blue"
        clouds.fill_color = "Blue"
    for k in range(position_x+25,window.width,100):
        clouds = GOval(40,30,x=k,y=position_y+20)
        window.add(clouds)
        clouds.filled = True
        clouds.color = "Blue"
        clouds.fill_color = "Blue"
    for l in range(position_x-25,window.width,100):
        clouds = GOval(40,30,x=l,y=position_y)
        window.add(clouds)
        clouds.filled = True
        clouds.color = "Blue"
        clouds.fill_color = "Blue"
    for m in range(position_x-25,window.width,100):
        clouds = GOval(40,30,x=m,y=position_y+20)
        window.add(clouds)
        clouds.filled = True
        clouds.color = "Blue"
        clouds.fill_color = "Blue"
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)
Beispiel #3
0
def face(dx=0, dy=0, main_color='greenyellow', necklace_color='purple'):
    """
    Function: draw face
    Principle: use ellipse subtraction to create curved shape
    :param dx: x-axis displacement
    :param dy: y-axis displacement
    :param main_color: main color
    :param necklace_color: necklace color
    """
    face = GOval(350, 200, x=dx + 135, y=dy + 135)
    face.filled = True
    face.color = main_color
    face.fill_color = main_color
    window.add(face)

    necklace = GOval(300, 70, x=dx + 160, y=dy + 270)
    necklace.filled = True
    necklace.color = necklace_color
    necklace.fill_color = necklace_color
    window.add(necklace)

    necklace_x = GOval(330, 100, x=dx + 145, y=dy + 215)
    necklace_x.filled = True
    necklace_x.color = main_color
    necklace_x.fill_color = main_color
    window.add(necklace_x)
Beispiel #4
0
def eye(window):
    """
    :param window:window
    """
    eye1 = GOval(30, 70, x=window.width / 2 - 32, y=window.height / 2 - 35)
    eye1.filled = True
    eye1.fill_color = "snow"
    window.add(eye1)
    eye11 = GOval(20, 40, x=window.width / 2 - 27, y=window.height / 2 - 5)
    eye11.filled = True
    window.add(eye11)
    eye2 = GOval(30,
                 70,
                 x=window.width - eye1.x - 23,
                 y=window.height - eye1.y - 70)
    eye2.filled = True
    eye2.fill_color = "snow"
    window.add(eye2)
    eye22 = GOval(20,
                  40,
                  x=window.width - eye11.x - 12,
                  y=window.height - eye11.y - 10)
    eye22.filled = True
    window.add(eye22)
    nose(window)
Beispiel #5
0
def ear(dx=0, dy=0, main_color='greenyellow', back_color='white'):
    """
    Function: draw ears
    Principle: use ellipse subtraction to create curved shape
    :param dx: x-axis displacement
    :param dy: y-axis displacement
    :param back_color: background color
    :param main_color: main color
    """
    l_ear = GOval(80, 150, x=dx + 80, y=dy + 150)
    l_ear.filled = True
    l_ear.color = main_color
    l_ear.fill_color = main_color
    window.add(l_ear)

    l_ear_x = GOval(40, 140, x=dx + 70, y=dy + 155)
    l_ear_x.filled = True
    l_ear_x.color = back_color
    l_ear_x.fill_color = back_color
    window.add(l_ear_x)

    r_ear = GOval(80, 150, x=dx + 460, y=dy + 150)
    r_ear.filled = True
    r_ear.color = main_color
    r_ear.fill_color = main_color
    window.add(r_ear)

    r_ear_x = GOval(40, 140, x=dx + 510, y=dy + 155)
    r_ear_x.filled = True
    r_ear_x.color = back_color
    r_ear_x.fill_color = back_color
    window.add(r_ear_x)
Beispiel #6
0
def dinosaur():
    dinosaur_img = GOval(250, 400, x=25, y=540)
    dinosaur_img.filled = True
    dinosaur_img.fill_color = 'green'
    dinosaur_img.color = 'green'
    window.add(dinosaur_img)
    dinosaur_head_img = GOval(230, 300, x=100, y=600)
    dinosaur_head_img.filled = True
    dinosaur_head_img.fill_color = 'green'
    dinosaur_head_img.color = 'green'
    window.add(dinosaur_head_img)
    dinosaur_eye_img = GOval(30, 50, x=200, y=585)
    dinosaur_eye_img.filled = True
    dinosaur_eye_img.fill_color = 'lightgreen'
    dinosaur_eye_img.color = 'lightgreen'
    window.add(dinosaur_eye_img)
    dinosaur_eye1_img = GOval(15, 15, x=212, y=590)
    dinosaur_eye1_img.filled = True
    dinosaur_eye1_img.fill_color = 'black'
    dinosaur_eye1_img.color = 'black'
    window.add(dinosaur_eye1_img)
    dinosaur_eye1_img = GOval(5, 5, x=222, y=590)
    dinosaur_eye1_img.filled = True
    dinosaur_eye1_img.fill_color = 'white'
    dinosaur_eye1_img.color = 'black'
    window.add(dinosaur_eye1_img)
Beispiel #7
0
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)
Beispiel #8
0
def eye():
    eye0 = GOval(50, 70, x=120, y=130)
    window.add(eye0)
    eye0.filled = True
    eye0.fill_color = 'yellow'
    eye1 = GOval(50, 70, x=180, y=130)
    eye1.filled = True
    eye1.fill_color = 'yellow'
    window.add(eye1)
Beispiel #9
0
def down_feet():
    down0 = GOval(70, 20, x=475, y=540)
    down0.filled = True
    down0.fill_color = 'pink'
    window.add(down0)
    down1 = GOval(70, 20, x=580, y=540)
    down1.filled = True
    down1.fill_color = 'pink'
    window.add(down1)
Beispiel #10
0
def monster_hand():
    m_hand0 = GOval(80, 50, x=440, y=300)
    m_hand0.filled = True
    m_hand0.fill_color = 'dark green'
    window.add(m_hand0)
    m_hand1 = GOval(80, 50, x=440, y=330)
    m_hand1.filled = True
    m_hand1.fill_color = 'dark green'
    window.add(m_hand1)
Beispiel #11
0
def monster_feet():
    foot0 = GOval(100, 40, x=460, y=520)
    foot0.filled = True
    foot0.fill_color = 'green'
    window.add(foot0)
    foot1 = GOval(100, 40, x=560, y=520)
    foot1.filled = True
    foot1.fill_color = 'green'
    window.add(foot1)
Beispiel #12
0
def monster_leg():
    leg0 = GOval(100, 60, x=520, y=480)
    leg0.filled = True
    leg0.fill_color = 'dark green'
    window.add(leg0)
    leg1 = GOval(100, 60, x=560, y=480)
    leg1.filled = True
    leg1.fill_color = 'dark green'
    window.add(leg1)
Beispiel #13
0
def arm():
    arm0 = GOval(70, 20, x=230, y=350)
    arm0.filled = True
    arm0.fill_color = 'silver'
    window.add(arm0)
    arm1 = GOval(70, 20, x=60, y=350)
    arm1.filled = True
    arm1.fill_color = 'silver'
    window.add(arm1)
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 #15
0
def draw(event):
    if event.x > window.width // 2:
        stroke = GOval(SIZE, SIZE)
        stroke.color = 'black'
        stroke.filled = True
        stroke.fill_color = stroke.color
    else:
        stroke = GOval(SIZE, SIZE)
        stroke.color = 'blue'
        stroke.filled = True
        stroke.fill_color = stroke.color
    for i in range(2):
        window.add(stroke, event.x + SIZE // 2, event.y + SIZE // 2)
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 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)
Beispiel #18
0
def painter(mouse):
    global counter, circle_point
    #on odd click, create circle on current location
    if counter is 0:
        circle = GOval(CIRCLE_SIZE,
                       CIRCLE_SIZE,
                       x=mouse.x - CIRCLE_SIZE / 2,
                       y=mouse.y - CIRCLE_SIZE / 2)
        circle.filled = False
        #record current circle location
        circle_point = (circle.x + circle.width / 2,
                        circle.y + circle.height / 2)
        window.add(circle)
        # increase counter to one in odd clicks
        counter += 1
    #on even click, draw line and remove circle
    else:
        #remove previous circle
        window.remove(window.get_object_at(circle_point[0], circle_point[1]))

        #draw a line from previous circle center to current mouse location
        line = GLine(circle_point[0], circle_point[1], mouse.x, mouse.y)
        window.add(line)
        #decrease counter to zero in even clicks
        counter -= 1
Beispiel #19
0
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 #20
0
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)
Beispiel #21
0
def make_a_ball():
    global ball
    new_ball = GOval(SIZE, SIZE, x=START_X, y=START_Y)
    new_ball.filled = True
    new_ball.fill_color = 'black'
    window.add(new_ball)
    ball = new_ball
Beispiel #22
0
def create_beeper(e):
    # create 4 beepers
    size = 50
    for i in (1, 3, 7, 9):
        beeper = GOval(size, size, x=i * 50 - size / 2, y=400 - size / 2)
        beeper.filled = True
        beeper.fill_color = 'blue'
        window.add(beeper)
    label1 = GLabel('001', x=50 - size / 2 + 9, y=400 - size / 2 + 37)
    label2 = GLabel('101', x=150 - size / 2 + 9, y=400 - size / 2 + 37)
    label3 = GLabel('201', x=350 - size / 2 + 9, y=400 - size / 2 + 37)
    label4 = GLabel('202', x=450 - size / 2 + 9, y=400 - size / 2 + 37)
    label1.font = '-15'
    label2.font = '-15'
    label3.font = '-15'
    label4.font = '-15'
    label1.color = 'white'
    label2.color = 'white'
    label3.color = 'white'
    label4.color = 'white'
    window.add(label1)
    window.add(label2)
    window.add(label3)
    window.add(label4)
    onmouseclicked(build_karel)
Beispiel #23
0
def bounce(m):
    global n, V, time, end
    if (time < 3) and (end == 0):
        window.clear()
        end = 1
        X = START_X
        Y = START_Y
        ball = GOval(SIZE, SIZE)
        ball.filled = True
        window.add(ball, X, Y)
        while X < 800:
            while Y < 500:
                n += 1
                pause(DELAY)
                window.clear()
                window.add(ball, X, Y)
                pause(DELAY)
                X = X + VX
                V = GRAVITY * n
                Y = Y + V
            V = V * 0.9
            n = 0
            while V > 0:
                n += 0.1
                X = X + VX
                V = V - GRAVITY * n
                Y = Y - V
                pause(DELAY)
                window.clear()
                window.add(ball, X, Y)
                pause(DELAY)
        window.add(ball, START_X, START_Y)
        time += 1
        end = 0
Beispiel #24
0
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)
Beispiel #25
0
    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)
Beispiel #26
0
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)
Beispiel #27
0
def nose(window):
    """
    :param window:window
    """
    nose_up = GOval(50, 20)
    nose_up.filled = True
    window.add(nose_up, x=window.width / 2 - nose_up.width // 2, y=245 + 40)
Beispiel #28
0
def main():
    """
    This program simulates a bouncing ball at (START_X, START_Y)
    that has VX as x velocity and 0 as y velocity. Each bounce reduces
    y velocity to REDUCE of itself.
    """
    global times,switch,VY
    ball=GOval(SIZE,SIZE,x=START_X,y=START_Y)
    ball.filled= True
    ball.fill_color='black'
    window.add(ball)
    switch = False
    onmouseclicked(turn_on)
    while True:
        pause(DELAY)
        if switch==True:
            VY+=GRAVITY
            ball.move(VX,VY)
            pause(DELAY)
            if ball.y>window.height:
                VY=-REDUCE*VY
            if ball.x>window.width:
                ball.x=START_X
                ball.y=START_Y
                times +=1
            if times>=3:
                break
        else:
            pass
Beispiel #29
0
def bouncing(m):
    global START_X, START_Y, VX, GRAVITY, DELAY, click, Time
    if Time > 0:
        # remove the ball at START_X and START_Y
        window.remove(ball)
        while click is True:  # The ball will not be influenced by click as moving
            # creating the ball at the next moving place
            ball2 = GOval(SIZE, SIZE, x=START_X + VX, y=START_Y + GRAVITY)
            ball2.filled = True
            window.add(ball2)
            # the primary down speed
            gravity = 0
            while True:  # the process of moving
                click = False
                gravity = gravity + GRAVITY
                ball2.move(VX, gravity)
                if ball2.y >= window.height:
                    gravity = -gravity
                    gravity = gravity * REDUCE
                    ball2.move(VX, gravity)
                pause(DELAY)
                if ball2.x > window.width:
                    break
            # back to the primary place
            window.add(ball)
            # count the time
            Time -= 1
        click = True
Beispiel #30
0
def karel_head():
    # Build Karel's head.
    global head
    head = GOval(60, 40, x=220, y=20)
    head.filled = True
    head.fill_color = 'gray'
    window.add(head)
    return head