A Python implementation for generating and visualizing Sierpinski triangles in 2D and 3D spaces. This project was developed as part of the Mathematical Modeling course.
- Clone the repository:
git clone https://github.com/yourusername/sierpinski-figures.git
cd sierpinski-figures
- Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
Or
pip install poetry
- Activate the virtual environment:
poetry shell
- Install project dependencies:
poetry install
- Admire the beauty of Sierpinski figures:
python '.\src\Sierpinski triangle.py'
python '.\src\Sierpinski pyramid.py'
This project provides tools for creating and visualizing various Sierpinski fractals, including:
- Interactive visualization
- Configurable iterations
- Color mapping options
- Full 3D rotation
- Zoom and pan controls
- Interactive vertex highlighting
- Generation of Sierpinski fractals
- 2D visualization using matplotlib
- 3D rendering with interactive rotation and zoom capabilities
- Efficient recursive implementation
- Support for saving generated figures as images
- Python 3.12+
- Poetry (Python package manager)
To execute the project and generate the Sierpinski figures, follow these steps:
- Ensure you have installed all dependencies as described in the Installation section.
- Activate the virtual environment:
poetry shell
- Run the Python scripts to generate the figures:
python '.\src\Sierpinski triangle.py'
python '.\src\Sierpinski pyramid.py'
Main dependencies managed by Poetry:
- numpy: Mathematical operations and array handling
- plotly: Interactive visualization of 2D and 3D figures
- pandas: Data manipulation and structuring
- matplotlib: 2D triangle visualization
- Sphinx: Documentation
from sierpinski.shapes_2d import SierpinskiTriangle
# Create a triangle with 6 iterations
triangle = SierpinskiTriangle(iterations=6)
fig = triangle.plot()
fig.show() # Opens in browser or notebook
fig.write_html("triangle.html") # Save as interactive HTML
from sierpinski.shapes_3d import SierpinskiPyramid
# Create a pyramid with 4 iterations
pyramid = SierpinskiPyramid(iterations=4)
fig = pyramid.plot_3d()
fig.show() # Opens interactive 3D visualization
fig.write_html("pyramid.html") # Save as interactive HTML
-
Interactive 2D or 3D rotation and zoom
-
Hover information showing coordinates
-
Screenshot capabilities
sierpinski-figures/
├── docs/ # Documentation files
├── index.md
├── sierpinski_pyramid.md
├── sierpinski_triangle.md
├── theory.md
└── usage.md
├── examples/
├── chaos_game.py
├── convergence_visualizer.py
└── converage_analyzer.py
├── src/
├── Sierpinski pyramid.md
├── Sierpinski triangle orgin.py
└── Sierpinski triangle.py
├── LICNESE.md
├── pyproject.toml # Poetry configuration and dependencies
├── poetry.lock # Lock file for reproducible
└── README.md
The Sierpinski figures are fractal sets that exhibit self-similarity at different scales. The project implements these mathematical concepts:
- Recursive subdivision of geometric shapes
- Iterative geometric transformations
This is a semester project for the Mathematical Modeling course. Feel free to use this code for educational purposes.
This project is licensed under the MIT License - see the LICENSE.md file for details.
Kacper Smyrak Magdalena Śnietura
Mathematical Modeling Course Silesian University of Science Faculty of Applied Mathematics