How to drop a ball
Imagine a ball of mass \(m\) and the goal to simulate and visualize its free fall with Python.
The Python code below uses the graphics library turtle to draw a ball.
ball is a turtle object and can be configured with the help of the color() and shape() methods.
Further, our ball object has got a method ball.ycor() that returns its current position along the \(y\)-axis, which we imagine as the balls height above the floor.
Other from that, the code contains an infinite loop while True: that is used to draw our ball over and over again.
Let’s give it a try and drop our digital ball! In the infinite loop, try to modify the position of the ball so it begins to fall:
- Use
ball.sety(val)to set the \(y\)-position ofballto a valueval - Use
ball.ycor()to get the current \(y\)-position ofball - Combine both steps to animate the
ball - What happens if you experiment with different values
val? - How close is your animation to reality?
First Steps:
Fancy a hint? You can find the solution here.
Since we are arbitrarily fantasising the speed of the ball, this is indeed not a physical simulation but just an animation. Let’s try to figure out how the ball should actually move!