PI approximation with Monte Carlo method.
- Draw a square.
- Draw a circle inside that square.
- Start drawing dots at a random place on the in the square.
- Count the dots that fall inside the circle:
dots_in_circle
.
# Approximate the area of the circle:
circle_area = screen_area * (dots_in_circle / total_dots)
# Use the circle_area approximation to calculate PI:
PI = circle_area / (self._circle.radius ** 2)
You can run the project with:
$ python compute_pi.py