A project that creates artistic images using pure mathematical formulas - no traditional graphics or drawing tools, just mathematical equations evaluated at each pixel.
| Original Image | Generated Image |
|---|---|
![]() |
![]() |
| Original snow-covered village | Mathematically generated village |
The mathematical equations for the snow-covered village were created by Hamid Naderi Yeganeh, an Iranian mathematical artist renowned for creating intricate artworks from mathematical formulas. This implementation brings his beautiful mathematical equations to life through code.
This project generates a beautiful snow-covered village scene entirely from mathematical formulas. Each pixel's RGB color value is computed using complex mathematical expressions involving trigonometric functions, exponentials, and various parameters.
math-drawings/
├── src/ # Source code
│ └── gen_math_village_img.py # Python script that generates the snow village image
├── resources/ # Images and other resources
│ ├── snow_covered_village_original.jpg # Original reference image
│ └── math-village-generated.png # Generated output image (2000x1200)
└── README.md
The script generates a 2000x1200 pixel image where each pixel's RGB color is defined by three functions H₀(x,y), H₁(x,y), and H₂(x,y) - one for each color channel (Red, Green, Blue). The implementation uses several mathematical components:
- E(x,y) - Fractal terrain texture using 40 iterations of scaled cosine functions
- B(x,y) - Background/ground mask that separates sky from terrain
- M(x,y) - Snow silhouette mask that creates the snow-covered effect
- Houses (s=1..67) - 67 individual house structures, each computed with:
- Coordinate transformations and rotations
- Window components (J_s)
- Wall components (K_s)
- Occlusion handling (Z variable)
- Uses NumPy vectorization for efficiency (loops over structures, not pixels)
- Normalized coordinates: x ∈ [-5/3, 5/3], y ∈ [-5/6, 5/6] (maps the 2000x1200 pixel space to a mathematical coordinate system centered at the origin)
- Safe exponential functions with clamping to avoid numerical overflow
- Each house has unique positioning, rotation, and detail based on its index
pip install numpy pillowSimply run the Python script:
python src/gen_math_village_img.pyThe script will:
- Generate the image (takes several seconds due to the complex calculations)
- Save the output as
resources/math-village-generated.png - Display progress and timing information
The generated image features:
- A snow-covered village with 67 houses
- Fractal terrain texture
- Atmospheric perspective
- Windows with lighting effects
- Snow accumulation on roofs
- All created purely from mathematical formulas!
Generation takes approximately 10-30 seconds depending on your CPU, with progress updates shown for the house generation phase (the most computationally intensive part).
This project demonstrates how complex, artistic images can be created using nothing but mathematical expressions. The entire scene - from the terrain texture to individual house windows - emerges from carefully crafted formulas evaluated at each pixel coordinate.

