

# FractalGen 🧩

**FractalGen** is a Python package for generating and visualizing fractal patterns like the Mandelbrot set, Julia set, Koch snowflake, Sierpinski triangle, and L-system fractals. Each fractal can be generated with a single function call.

---

## 📦 Installation

Install from PyPI (after publishing):

```bash
pip install fractalgen
````

Or install from source:

```bash
git clone https://github.com/bhuwankhatri/fractalgen.git
cd fractalgen
pip install -e .
```

---

## 🌀 Fractal Patterns

### 🟡 Mandelbrot Set

The Mandelbrot set is generated by checking which complex numbers remain bounded under a recurrence formula. It produces the iconic cardioid shape with infinite detail.

![Mandelbrot](./assets/mandelbrot.png)

---

### 🟣 Julia Set

Julia sets are variations of the Mandelbrot fractal, defined using a fixed complex constant. Different constants produce different fractal "personalities".

![Julia](./assets/julia.png)

---

### ❄️ Koch Snowflake

The Koch snowflake begins as an equilateral triangle. Each side is recursively replaced with a spike pattern, creating a snowflake boundary.

![Koch](./assets/koch.png)

---

### 🔺 Sierpinski Triangle

A classic example of a recursive fractal made by repeatedly removing the center of a triangle. The pattern reveals a triangular lattice structure.

![Sierpinski](./assets/sierpinski.png)

---

### 🌿 L-System Fractal

L-Systems (Lindenmayer Systems) use rewriting rules to simulate fractal growth like that of plants, corals, and trees.

![L-System](./assets/lsystem.png)

---

## ✏️ Example Usage

Here’s how to generate and save a Mandelbrot image:

```python
from fractalgen import generate_mandelbrot, plot_mandelbrot

div_time = generate_mandelbrot()
plot_mandelbrot(div_time, save_path="mandelbrot.png", show=False)
```

Every fractal module provides two functions:

* `generate_*`: Computes data (e.g., image matrix or point list)
* `plot_*`: Renders or saves the fractal image

---

## 📁 Folder Structure

```
fractalgen/
├── fractalgen/
│   ├── mandelbrot.py
│   ├── julia.py
│   ├── koch.py
│   ├── sierpinski.py
│   ├── lsystem.py
│   └── __init__.py
├── examples/
├── tests/
├── assets/
│   └── *.png
├── README.md
├── LICENSE
└── pyproject.toml
```

---

## 🧪 Run Tests

To verify everything works:

```bash
pytest tests/
```

---

## 🤝 Contributing

Fractals are fun and there's room for more! Contributions are welcome — add new fractal types, optimize existing ones, or improve rendering. Fork the repo and open a pull request.

---

## 📄 License

MIT License © 2025 Bhuwan Khatri

