For Pi Day (3/14) of 2019, I decided to create a tweetcart showcasing the Monte Carlo method of approximating pi. This method calculates the distance between the origin and a random point from (r,r) to (r,r), where r is the radius (in this case, 1). Then, the total number of dots within the circle (or, within a distance of r) is divided by the total number of dots. Multiply that number by 4, and you get pi!
Here, I only render a fourth of the circle; it works the same way. Every frame, the program places 20 random dots on the canvas. If a dot is within 1 unit of the origin, then it becomes blue; else, it becomes red. Pi is 4 times the number of blue dots over the number of total dots. Pico8 uses a 16bit fixedpoint type for its numbers, though, so it’s not particularly accurate; still, I enjoyed learning about and demonstrating this method!
A tweetcart is a Lua script that can run in Pico8 and fit within a single Tweet, with 280 characters or fewer.
