Draw Spiral Shapes using Python Turtle

Spiral Shapes using Python Turtle

Introduction

Hello everyone, welcome to copyassignment.com, Our topic of today’s session is drawing the simple and easy spiral shapes in the python turtle module. Don’t worry, the code is very small and easy to understand and the output is very fascinating.

We have given the proper explanation of the code for each block as well as provided the comments for the code wherever necessary.

So let’s begin

Import Turtle

import turtle
import turtle as t

Importing the turtle module allows us to use its inbuilt methods and functions in our program. Here we have imported turtle as t so that we can access its function using the t variable.

Setting the turtle object for spiral shapes

#set speed of the turtle
t.speed(20)
pattern=0

#set the screen to pink color
scr=turtle.Screen()
scr.bgcolor("pink")

In this part, we have set the speed of the turtle 20. The pattern variable is set to 0, set the screen object as scr. Set the background color to pink.

 Draw the spiral shapes using for loop

for i in range(100):
    for color in  ["blue","green"]:
        t.color(color)
        t.forward(pattern)
        t.right(90)
        t.right(1)
        pattern+=1

turtle.done()

In this last section we actually draw our spiral shapes, we have set the for loop to range 100 so that the color can be reflected in the design 100 times. We have made use of 2 colors that is green and blue . Color is reflected alternately for each loop. The forward(pattern) is nothing but allowing how many steps forward the line of the pattern should move. The right represents the angle.

Complete Code to draw Spiral Shapes using Python Turtle

#Import turtle
import turtle
import turtle as t

#set speed of the turtle
t.speed(20)
pattern=0

#set the screen to pink color
scr=turtle.Screen()
scr.bgcolor("pink")


for i in range(100):
    for color in  ["blue","green"]:
        t.color(color)
        t.forward(pattern)
        t.right(90)
        t.right(1)
        pattern+=1

turtle.done()

Output

Output of Spiral Shapes using Python Turtle
Spiral Shapes using Python Turtle

You can see how beautiful it looks, hence we have successfully generated the Spiral Shapes using Python Turtle. Please let us know your feedback by leaving comments in the comment box.

Thank you for reading this article.


Also Read:


Keywords->python turtle design, turtle, design, 12th class python project, python for kids, 12th class, beautiful turtle designs, python, class 12th, class 12

Share:
Avatar of pranjal dev

Author: pranjal dev