This Python project is a Pygame-based tool for interactively tracing shapes on a map and estimating their real-world area using a Monte Carlo sampling method. It was originally created as a demonstration tool to challenge flat-Earth proponents, by allowing users to draw regions on a "flat Earth" map and compute their real surface area — revealing inconsistencies that arise from projecting a spherical Earth onto a 2D plane.
- Draw custom contours (polygons) with the mouse
- Set a real-world scale by clicking on a map's known distance (e.g., a scale bar)
- Estimate the enclosed area (in km²) using Monte Carlo integration
- Real-time updates during computation
- Handles open contours by automatically treating them as closed for the area calculation
- Python 3.x
- Pygame (install via
pip install pygame)
-
Clone or download this repository.
-
Ensure you have Pygame installed:
pip install pygame
-
Modify the image path in the code to point to your local map image file:
image_path = "/your/path/to/flat_earth.png"
-
Run the script:
python your_script.py
- Left-click and drag to draw a contour (polygon) on the map.
- The red line represents your current region.
- Release the mouse button to complete the trace.
- You can draw multiple traces if needed.
Note: Even if your trace appears open, the Monte Carlo method treats the region as closed by logically connecting the first and last points.
To convert from pixels to kilometers, you must define the scale:
- Press
Enterto enter scale measurement mode. - Left-click once at the start of the scale bar on the map.
- Left-click again at the end of the scale bar.
- A green line will appear, and you will be prompted to type the real-world distance in kilometers (e.g.,
100). - Press
Enteragain to validate.
This sets the pixel-to-kilometer ratio used for accurate area estimation.
- Once you've drawn your contour and set the scale, press
Enteragain to launch the Monte Carlo simulation. - The tool randomly generates 100,000 sample points within the bounding box of your region and tests whether they lie inside the drawn shape.
- The estimated area in km² will be shown at the top-left of the screen and printed in the terminal.
- The tool loads a custom map image (
.png) and uses its dimensions to size the Pygame window. - Drawing is layered on top of the map surface.
- Traces are recorded as lists of point tuples (x, y).
- All user-drawn traces are stored in the
traceslist. - Each time the mouse is moved while pressed, new points are added to the current trace.
- When measuring is enabled, two mouse clicks are interpreted as endpoints of a known-length segment.
- The pixel distance between these two points is computed and stored.
- The user is prompted to input the real distance in kilometers.
- A ratio (
scale_ratio) is calculated in km/pixel and used for area conversion.
- The bounding box of all points is computed.
- 100,000 random points (
num_samples = 100000) are generated inside this bounding box. - Each point is tested using the ray casting algorithm to determine if it lies inside the polygon.
- The ratio of points inside the region vs. total samples gives the approximate pixel area.
- This area is converted to km² using the square of the scale ratio.
- Even if the drawn contour is visually open, it is treated as closed by connecting the last point back to the first during inside/outside testing.
- This ensures the region is always interpreted as a proper polygon for area calculation.
| Key / Action | Function |
|---|---|
| Left Click & Drag | Draw a contour |
Enter |
Toggle between drawing, measuring, and launching estimation |
Delete |
Remove last trace |
Backspace |
Edit typed scale value |
Escape |
Quit the program |
Using a "flat Earth" map (azimuthal equidistant projection), you can:
- Trace the actual shape of a continent or region.
- Define a known scale from the map's scale bar.
- Compute the estimated area.
- Compare it to the real-world value to illustrate distortion due to projection — an inconsistency in the flat Earth model.
- The estimation is probabilistic and might vary slightly due to randomness.
- The accuracy depends on the number of samples (set to 100,000 by default).
- It currently supports only 2D polygon tracing; no elevation or 3D projection handling.
This tool was developed to visually and mathematically challenge the flat Earth model by Hugo Alexandre (@Hugo_GW), demonstrating how projected maps distort real distances and areas. By using actual map scales and comparing computed areas, it serves as a simple but powerful educational and debunking tool.
Here are some illustration to understand how the code works and the several steps to estimate surfaces and aeras
