Skip to content

lily-n20/Recursive-Graphics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recursive-Graphics

Recursive graphics are composed of a simple shape being drawn repeatedly to form complex and captivating images. Through the iterative process of recursion, fractals are created and repeated to create a larger image. Many of these graphics mesmerizing patterns are well known among math and computer science as understanding how recursion works is important to problem solving and realizing how code can be reused to create elegant solutions.

In our project, we explore the three recursive fractals: Sierpinski triangle, Koch Snowflake, and the Hilbert Curve by utilizing Python Turtle to visualize our C++ program. We chose recursive graphics because we wanted to explore recursion more in depth. We also enjoyed the visualization aspect of the project where we could creatively implement code. We utilized Python Turtle to visualize our fractals and implemented the recursive algorithms to generate the patterns for the L-system in C++.

Python Setup

pip install matplotlib (if computer uses python)
pip3 install matplotlib (if computer uses python3)

if an upgrade is needed, run the command:

pip install --upgrade pip (if computer uses python)
pip3 install --upgrade pip (if computer uses python3)

l-system-plotter.py

The Python implementation is a very simple program that reads the L-System files generated by the other programs and uses turtle graphics to plot the fractals. The Python code is split into 5 functions: plot_coords, print_coords turtle_to_coords, run_turtle_program, and get_color_input.

Sierpinski Triangle

This cpp file writes commands to a text file to produce the Sierpinski Triangle fractal. The libraries needed in order to run this are string, iostream, and fstream. To create the l-system.txt file:

g++ STriangle.cpp -o sTriangle
./sTriangle <num of levels>

To plot the l-system into a viewable image:

python3 l-system-plotter.py l-system.txt sierpinski 120

The l-system-plotter.py will then prompt you for a background color and then plot color. The color options that are available are listed below.

Koch Snowflake

This cpp file writes commands to a text file to produce the Koch curve fractal. The libraries needed in order to run this are string, iostream, and fstream. To create the l-system.txt file:

g++ koch.cpp -o ksnowflake
./ksnowflake <num of levels>

To plot the l-system into a viewable image:

python3 l-system-plotter.py l-system.txt kSnowflake 60

The l-system-plotter.py will then prompt you for a background color and then plot color. The color options that are available are listed below.

Hilbert's Curve

This cpp file writes commands to a text file to produce the Hilbert Curve fractal. The libraries needed in order to run this are iostream and fstream. When compiling this file you should use this command:

g++ hilbert.cpp -o hilbert
./hilbert l-system.txt <num of levels>

To plot the l-system into a viewable image:

python3 l-system-plotter.py l-system.txt hilbertCurve 90 

The l-system-plotter.py will then prompt you for a background color and then plot color. The color options that are available are listed below.

L-System Plotter

The L-System plotter comes with the functionality of asking the user for a color for the plot background and lines. The list of available colors can be found here:

image

About

CSC 212 Final Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •