Durham Hackathon

A short intro to numerical simulation

View on GitHub

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:

  1. Use ball.sety(val) to set the \(y\)-position of ball to a value val
  2. Use ball.ycor() to get the current \(y\)-position of ball
  3. Combine both steps to animate the ball
  4. What happens if you experiment with different values val?
  5. 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!

Next step