This project demonstrates how to use the Python turtle
graphics library to draw a recursive star pattern. The pattern is drawn using a series of smaller stars within a larger star, creating a fractal-like design.
- main.py: The main script containing the code to draw the recursive star pattern.
To run this project, you'll need to have Python installed on your machine along with the turtle
module. The turtle
module is a standard Python library, so no additional installation is usually required. However, if you're using an environment that doesn't include turtle
, you can install it using:
pip install PythonTurtle
-
Clone the repository or download the script file.
-
Run the script using Python:
python main.py
-
The program will open a window and display the recursive star pattern.
The main components of the code are:
-
Setup: The turtle is initialized, and the screen background is set to black.
-
Drawing the Star: The
star
function is a recursive function that draws a star pattern. It takes a turtle object and a size as parameters. The function draws a star, then calls itself with a smaller size to draw smaller stars at each point. -
Color and Speed: The turtle's color is set to yellow, and the drawing speed is set to 25 for a faster rendering.
-
Color: You can change the color of the star by modifying the
a.color("yellow")
line in the code. -
Size: The size of the initial star can be adjusted by changing the argument passed to the
star
function. -
Position: The starting position of the turtle can be changed by modifying the
a.goto(-200, 100)
line.
This project is open-source and available under the MIT License.