monto.carlo.mp4
This project visualizes the process of estimating the value of Pi using the Monte Carlo method. It uses random point generation within a square that bounds a circle to approximate Pi.
The visualization includes:
- Red points: Represent points inside the circle.
- Green points: Represent points outside the circle.
- A progress bar: Displays the simulation progress.
- Real-time updates: Shows the current Pi estimate and error rate compared to the true value of π.
- Initialize
circle_points
,square_points
, andinterval
to 0. - Generate a random point
x
. - Generate a random point
y
. - Calculate ( d = x * x + y * y ).
- If ( d <= 1 ), increment
circle_points
. - Increment
square_points
. - Increment
interval
. - If
interval
<NO_OF_ITERATIONS
, repeat from step 2. - Calculate pi = 4 * (circle_points / square_points).
- Terminate.
- Dynamic Point Generation:
- Points are randomly generated and drawn in batches for efficiency.
- Interactive Visualization:
- Displays points on a canvas in real-time.
- Progress Feedback:
- A progress bar tracks the completion percentage of the simulation.
- Real-Time Insights:
- Displays the estimated Pi value and the error rate dynamically.
- HTML5: For structuring the page and creating the canvas element.
- CSS3: For styling the visualization and progress bar.
- JavaScript: For implementing the Monte Carlo algorithm and visualization logic.
- Clone or download the repository.
- Open the
index.html
file in any modern browser. - Click the "Start Simulation" button to begin.
- Observe:
- The canvas updates with red and green points.
- The progress bar indicates the simulation progress.
- Real-time Pi estimate and error rate updates.
- Approximated the value of Pi using 1,000,000 random points.
- Achieved an estimated value of Pi close to 3.1412, with a minimal error rate.
- Created an interactive and educational visualization of Pi estimation.