Draw Colourful Star Pattern in Turtle – Python
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. modules required:
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:
Please Login to comment...