Turtle library enables users to draw pictures 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. In this article, we will generate a circular pattern out of squares using Python's turtle module.
Examples:Pattern for different number of squaresApproach:
For drawing the circle, we need to draw n number of square, each time rotating the turtle cursor by d degrees. n and d are chosen such that n*d=360, so as to complete a full circle. In the implementation below we will draw a circle of 60 squares, rotating the cursor each time by 6 degrees.
Functions used:
fd(x) : draw the cursor forward by x pixels.
rt(x) : rotates the facing direction of the cursor by x degrees to the right.
Below is the implementation.
Python3 1==
fromturtleimport*# loop for number of squaresforiinrange(60):# loop for drawing each squareforjinrange(4):# drawing each side of# square of length 100 fd(100)# turning 90 degrees# to the rightrt(90)# turning 6 degrees for# the next squarert(6)
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.