Many Circle Rings Design|Python Turtle

Many Circle Rings Design|Python Turtle

In this article, we will be learning about a very cool and different Many Circle Rings Design using Python Turtle. The code for the turtle program is given below. Accordingly, this article will explain to you how you can code in turtle that will allow you to create some circle rings. We will first see the code and then, we will understand it line-by-line. Now let’s see the code for design.


Code:


import turtle
turtle.bgcolor("black")
painter = turtle.Turtle()
painter.speed(0)
painter.penup()
painter.left(90)
painter.goto(0,0)
painter.forward(100)
painter.left(180)
painter.pendown()
j=0
while(j<=5):
    
    painter.pencolor("red")
    for i in range(150):
        painter.forward(100)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("dark blue")
    for i in range(150):
        painter.forward(102)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark violet")
    for i in range(150):
        painter.forward(104)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("dark red")
    for i in range(150):
        painter.forward(106)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark orange")
    for i in range(150):
        painter.forward(104)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("dark blue")
    for i in range(150):
        painter.forward(102)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark grey")
    for i in range(150):
        painter.forward(100)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("red")
    for i in range(150):
        painter.forward(100)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("dark blue")
    for i in range(150):
        painter.forward(102)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark violet")
    for i in range(150):
        painter.forward(104)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()
 
    painter.pencolor("dark red")
    for i in range(150):
        painter.forward(106)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark orange")
    for i in range(150):
        painter.forward(104)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

    painter.pencolor("dark blue")
    for i in range(150):
        painter.forward(102)
        painter.right(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(180*j)
    painter.pendown()

    painter.pencolor("dark grey")
    for i in range(150):
        painter.forward(100)
        painter.left(111) # Let's go counterclockwise this time
    painter.penup()
    painter.right(90*j)
    painter.pendown()

j=j+1
turtle.done()
turtle.quit()
j=j+1
turtle.done()
turtle.quit()




Output:



Explanation:

First Part:

  • First, import the turtle module and set the background color to black.
  • Then, let the painter variable start the turtle and set the speed to 0 and the function penup is called. After the pen turns left by 90 degrees, the pen is sent to (0, 0), forward to 100, and finally left to 180 degrees. The pen is kept down.
  • A variable “j” is set to 0. Afterward, a while loop is called where the loop runs until the value of j is equal or less than 5.

Second Part:

  • Inside the while loop, first, the pen color is set to red, and a for loop with the range of 150 is called. And inside this loop, the painter is sent forward at about 100 and left at about 111 degrees. This will make the pen go counterclockwise. 
  • The pen is lifted and is sent right at the angle of j multiplied by 90. However, the first time, the j is 0 so the pen is right next. After, the pen is kept down.
  • Again, the pen color is set to dark blue and a for loop of range 150 is called. Here, first, the pen is sent forward at a value of 150 and right at an angle of 111 degrees. Then the pen is lifted and rotated 90 degrees. 
  • Sequentially, another for loop where the pen color is dark violet is called. Harem the painter is sent forward at a value of 104 and left at an angle of 111 degrees. Then the pen is lifted and the same as before.
  • Similarly, another for loop with the range of 150 where the background color is dark is red is called, Here, the pen is sent forward at a value of 106 and right at an angle of 111 degrees. Then the pen is kept down and rotated at an angle of j multiplied by 180 and the pen is put down.
  • Likewise, next for loop of range 150 and the pen color of dark orange is called. Here, the painter is sent forward at a value of 104 and left at an angle of 111 degrees. Then the pen is lifted and rotated anticlockwise right at an angle of j multiplied by 90 and the pen is put down.
  • Accordingly, another for loop with the range of 150 and the pen color if dark blue is called. Here, the pen is sent forward at a value of 102 and right at an angle of 111 degrees. Then the pen is lifted and rotated at an angle of j multiplied by 180 and the pen is kept down.
  • All the other for loops are written in the same manner. But the background color and the value of degrees are changed.

Last Part:

  • When the loop is broke, j is added by 1 and the turtle is quit and the same thing is done twice.

Comment your queries or anything you want to know or tell us based on this post or website.


Keep Learning


Also read:


Python Turtle Design in Indian Flag Color

Python Turtle Beautiful Design

Guess the Number Python

Snake Game in Python using Pygame

Rock Paper Scissor Game Using Python Tkinter

Password Generator Application In Python

Colored Hexagons Turtle Design


Share:

Author: Ayush Purawr