I want the dot to change direction when it hits the wall. I don't know what the problem is. #3846
-
class FunctionTracpo(Scene):
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
can you please format your code correctly by enclosing it between triple backticks as described here: |
Beta Was this translation helpful? Give feedback.
-
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(
Create(ball), Create(box) ,
)
ball.add_updater(update_circle)
self.wait(5, frozen_frame=False) |
Beta Was this translation helpful? Give feedback.
-
You might want to modify your direction-changing equations a bit... we recently had a similar discussion on Discord... |
Beta Was this translation helpful? Give feedback.
ok, here is a working code: