Pi-Calculating Simulation Using Boxes

by wc658356 in Circuits > Computers

124 Views, 1 Favorites, 0 Comments

Pi-Calculating Simulation Using Boxes

image_2026-03-31_215351596.png
image_2026-03-31_212120667.png

My project uses bouncing blocks to calculate a set number of digits of pi.

Supplies

Pycharm, computer, mouse, and keyboard

Make a Prompt for the Calculation

Screenshot 2026-03-31 211215.png

This section of code asks for the amount of digits to calculate and provides a backup for an invalid number of digits.

Make a Window for the Simulation

Screenshot 2026-03-31 211228.png

This makes a window that is 1000x600 pixels and defines a font and a way to find the amount of time the simulation has been running.

Find All the Parameters of the Objects

Screenshot 2026-03-31 212919.png
Screenshot 2026-03-31 213149.png

This defines the mass, friction, elasticity, size, and hitbox of all objects in simulation

Define Traits of the Collision

image_2026-03-31_213523595.png

This ensures that the collisions that occur in the simulations don't change the shape of the objects and that the collisions don't lose energy

Ensure That As the Simulation Continues, the Objects Keep Moving

Screenshot 2026-03-31 214107.png
Screenshot 2026-03-31 214117.png

The first part of this code compares the variable epsilon to the time left in the simulation. The next part measures the time it takes for the box to get to the wall. Then, the code finds the relative speed when compared to each other. Then it measures the time between each collision to determine if there will be another collision before the simulation ends. The last part determines the velocity if you add friction to the simulation.

Make the Screen

Screenshot 2026-03-31 215008.png
image_2026-03-31_215036748.png

This draws all elements of the simulation and puts a piece of text that counts the collisions for the calculation.