Skip to content

I want the dot to change direction when it hits the wall. I don't know what the problem is. #3846

Answered by uwezi
jengelbertt asked this question in Q&A
Discussion options

You must be logged in to vote

ok, here is a working code:

class FunctionTracpo(Scene):
    def construct(self):

        width=5
        height=5
        box=Rectangle(height=height , width=width )
        box.set_stroke(width=2)

        ball=Dot()
        ball.vx , ball.vy = 0.05 , 0.05

        def update_circle(c):
            right_point=c.get_right()[0]
            left_point=c.get_left()[0]
            top_point=c.get_top()[1]
            bottom_point=c.get_bottom()[1]

            if right_point >= width/2 or left_point <= -width/2:
                c.vx *=-1

            if top_point > height/2 or bottom_point < -height/2:
                c.vy *=-1


            c.shift(c.vx*RIGHT + c.vy*UP)

        self.play(…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jengelbertt
Comment options

Answer selected by jengelbertt
Comment options

You must be logged in to vote
2 replies
@jengelbertt
Comment options

@uwezi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants