Skip to content

Matin-python/Barnsley

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Barnsley Fern Fractal

A Python project that generates the Barnsley Fern fractal using an Iterated Function System (IFS). The repository contains two different implementations that produce the same fractal using different visualization methods.

Features

  • Generates the Barnsley Fern fractal
  • Uses probabilistic affine transformations
  • Two visualization approaches
  • Demonstrates fractal geometry and chaos theory concepts
  • Built with Python and NumPy

Implementations

1. Turtle Graphics Version

File: Barnsley (turtle).py

Draws the fractal point-by-point using Python's built-in Turtle Graphics library.

Advantages:

  • Easy to understand
  • Visualizes the drawing process in real time
  • Suitable for learning fractal generation

2. Matplotlib Version

File: Barnsley (matplotlib).py

Generates points and plots them using Matplotlib.

Advantages:

  • Faster rendering
  • Handles larger numbers of points efficiently
  • Produces cleaner visualizations

Requirements

Install the required packages:

pip install numpy matplotlib

The Turtle version only requires NumPy because Turtle is included with Python.

How to Run

Turtle Version

python Barnsley (turtle).py

Matplotlib Version

python Barnsley (matplotlib).py

Example Output

The program generates the famous Barnsley Fern fractal, a mathematical structure that resembles a natural fern leaf.

Turtle Version Matplotlib Version

How It Works

The Barnsley fern is generated by repeatedly applying one of four affine transformations.

At each iteration:

  1. A transformation is selected according to a probability distribution.
  2. New coordinates are calculated.
  3. The resulting point is plotted.
  4. Repeating this process thousands of times creates the fern shape.

Technologies Used

  • Python 3
  • NumPy
  • Turtle Graphics
  • Matplotlib

Learning Objectives

This project demonstrates:

  • Fractal generation
  • Iterated Function Systems (IFS)
  • Randomized algorithms
  • Data visualization
  • Mathematical programming

Future Improvements

  • Interactive GUI
  • Adjustable probabilities
  • Animation controls
  • Multiple fractal types
  • High-resolution image export

License

This project is licensed under the MIT License.

Author

Mohammad Reza Bakhshandeh

Electrical Engineering (Electronics) Graduate

Interested in Python Development, Computer Vision, Machine Learning, and Artificial Intelligence.

About

A Python implementation of the Barnsley Fern fractal using probabilistic affine transformations, visualized with Turtle Graphics and Matplotlib.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages