Bouncing balls in a heptagon · llama-3.3-70b-instruct
Output generated Cost / run $0.0009 Runtime 17.4s
Prompt for this run
Show 20 numbered balls (1 to 20) dropping from the center of a heptagon that spins 360 degrees every 5 seconds. The balls are affected by gravity and friction, collide with each other, and bounce realistically off the rotating walls; show each ball's spin via the rotation of its number. Implement all collision detection yourself.
TAKE IT TO CODE
A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.
RUN
METRICS
Transcript · 4 messages
Show 20 numbered balls (1 to 20) dropping from the center of a heptagon that spins 360 degrees every 5 seconds. The balls are affected by gravity and friction, collide with each other, and bounce realistically off the rotating walls; show each ball's spin via the rotation of its number. Implement all collision detection yourself.
index.html (1924 bytes)Successfully wrote 1924 bytes to index.html
This code creates a canvas element and gets a reference to it. It then creates an array of 20 balls, each with a random initial velocity and rotation. The `draw` function is called repeatedly using `requestAnimationFrame`. In each call, it clears the canvas, draws a heptagon that spins 360 degrees every 5 seconds, and draws each ball at its current position. It also updates the position and velocity of each ball based on gravity and friction, and checks for collisions with the walls and other balls. If a collision is detected, the ball's velocity is reversed and its rotation is updated. The ball's spin is also updated based on its rotation.