Ordinate 2D Marketplace Community Open the studio

Marketplace › From Ordinate 2D

One ball falling on every world

Script by Ordinate 2D ✓ · Mechanics

The same 10 m drop on the Moon, Mars, Earth, Jupiter and the Sun, timed against t = √(2h/g).

Use in Ordinate 2DOpens in the Script tab: it runs when you press Run. Free, no account needed.
"""One ball dropped from 10 m on every world: t = √(2h/g).

The gravity changes after each landing (Moon, Mars, Earth, Jupiter, the Sun's surface); the script times each fall and writes it
next to the formula. Press Play again to watch the same ball fall on the next world.

Runs in the studio (Script tab → Run) and locally:  python3 falling_on_worlds.py
"""
import math
import studio as s

H, R = 10.0, 0.15
WORLDS = [("Moon", 1.62), ("Mars", 3.71), ("Earth", 9.81), ("Jupiter", 24.79), ("Sun", 274.0)]

s.clear()
s.ground(0, width=8, restitution=0)
ball = s.circle(0, H + R, R, mass=1, name="Ball", color="#4f8ff7", restitution=0)
state = {"i": 0, "t0": 0.0, "vy": 0.0}


def drop():
    name, g = WORLDS[state["i"]]
    s.gravity = (0, -g)
    ball.position = (0, H + R)
    ball.velocity = (0, 0)
    print(f"{name}: g = {g} m/s²")


@s.on_start
def begin():
    state["i"], state["t0"] = 0, 0.0
    drop()


@s.on_step
def watch(t, dt):
    previous_vy, state["vy"] = state["vy"], ball.vy
    if ball.y <= R + 0.002 and t - state["t0"] > 0.05:
        name, g = WORLDS[state["i"]]
        fall = t - state["t0"]
        s.record(g=g, fall_time=fall, theory=math.sqrt(2 * H / g), landing_speed=-previous_vy, theory_speed=math.sqrt(2 * g * H))
        print(f"   fell in {fall:.3f} s (theory {math.sqrt(2 * H / g):.3f} s)")
        state["i"] += 1
        state["t0"] = t
        if state["i"] >= len(WORLDS):
            s.stop()
        else:
            drop()


s.run(30)

table gravity presets experiment