[Python] is the code on the right track if exercise ask to have just a ball bouncing around on...

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    #I'm trying to make a ball that bounce around and when reach the edged of the window change direction , as the exercise is asking to me , have you clues about how to think to accomplish this ?

    def ball():
    print("This program will show a ball bouncing around within the window")


    update(100)

    win = GraphWin("Ball",400,400)
    win.setBackground("white")
    win.setCoords(-10,-10,10,10)
    dx = 1
    dy = 1

    for _ in range(10000):

    ball = Circle(Point(dx,dy),2)
    ball.setFill("black")
    ball.draw(win)
    dx += 1
    dy += 1

    if dx >= 8:
    dx = -1
    elif dx <= -8:
    dx = 1

    if dy >= 8:
    dy = -1
    elif dy <= -8:
    dy = 1
    ball.undraw()

    ball()

    Continue reading...

Compartilhe esta Página