Marketplace › From Ordinate 2D
Build a scene in a loop: a pyramid of boxes
A pyramid made by loops, then a heavy ball thrown at it.
Use in Ordinate 2DOpens in the Script tab: it runs when you press Run. Free, no account needed.
"""Build a scene in a loop: a pyramid of boxes, then a heavy ball knocks it over.
Runs in the studio (Script tab → Run) and locally: python3 build_stack.py
"""
import studio as s
ROWS, W, H = 7, 0.4, 0.3 # rows, box width and height (m)
s.clear()
s.ground(0, width=24)
for row in range(ROWS):
n = ROWS - row
for k in range(n):
x = (k - (n - 1) / 2) * (W + 0.02)
s.box(x, H / 2 + row * H, W, H, mass=0.5, name=f"Box {row + 1}.{k + 1}", color="#4f8ff7" if row % 2 else "#8ab8ff")
ball = s.circle(-6, 0.6, 0.3, mass=12, name="Ball", color="#e5484d", velocity=(9, 1.5))
print(f"{len(s.bodies()) - 2} boxes")
s.run(6)