DEV Community

Cover image for Finding Areas Using the Monte Carlo Method
Victor Ribeiro
Victor Ribeiro

Posted on

1

Finding Areas Using the Monte Carlo Method

Finding Areas Using the Monte Carlo Method

Using the Monte Carlo Method to find the area of an drawn image.

Monte Carlo Method

Live version here

About

Draw an image, run the monte carlo method to calculate it's area. Increase or decrese the number of samples used in the simulation. I have written a similar code that runs the simulation several times and get the mean of them all. I like this one better. The canvas is 500x500 pixels. So, if you color it all and click solve, you should get a result of 250000 pixels.

How to use it

Canvas - Draw the image you want to calculate the area from.

Input - Enter the number of samples to be used in the simulation, in the input box.

Solve - Click to solve the aproximate area of the drawn image. You can click solve multiple times to get different results.

Clear - Clear the canvas.

Take a look at the code here

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs