In this article we will use Python’s turtle library to draw a spiral of stars, filled with randomly generated colours. We can generate different patterns by varying some parameters.
turtle library enables users to draw picture or shapes using commands, providing them with a virtual canvas.
turtle comes with Python’s Standard Library. It needs a version of Python with Tk support, as it uses tkinter for the graphics.
First we set each of the parameters for the spiral: number of stars, exterior angle of the stars and angle of rotation for the spiral. The colours are chosen randomly by choosing three random integers for rgb values, and so each time we get a different colour combination.
In the implementation below, we will draw a pattern of 30 stars, with exterior angle 144 degrees and angle of rotation 18 degrees.
By changing the exterior angle to 72, we can get a pattern of pentagons as such:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Draw Spiraling Star using Turtle in Python
- How to draw color filled star in Python-Turtle?
- Python - Draw Star Using Turtle Graphics
- Draw Black Spiral Pattern Using Turtle in Python
- Star fractal printing using Turtle in Python
- Draw Circle in Python using Turtle
- Draw Square and Rectangle in Turtle - Python
- Draw Color Filled Shapes in Turtle - Python
- Draw any polygon in Turtle - Python
- Draw Cube and Cuboid in Python using Turtle
- Draw Shape inside Shape in Python Using Turtle
- Draw Colored Solid Cube using Turtle in Python
- Draw Panda Using Turtle Graphics in Python
- Draw Heart Using Turtle Graphics in Python
- Draw Ellipse Using Turtle in Python
- Draw Graph Grid Using Turtle in Python
- Draw Dot Patterns Using Turtle in Python
- Draw Chess Board Using Turtle in Python
- Draw Spiraling Polygon using Turtle in Python
- Draw Spiraling Square using Turtle in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.