
Introduction
Hello everyone, welcome to copyassignment.com. In this article, we are learning to draw Virus using Python Turtle module. It’s a simple, cool, and easy python project for beginners learning the python turtle. We are providing the source code along with the output for your reference. We are also providing a detailed explanation for the code.
So let’s start to draw a vibrating circle.
Import Turtle
import turtle
Import function imports the turtle module for the project to access its methods and functions.
Initialize the turtle object to access the Turtle functions
tt=turtle.Turtle() turtle.bgcolor("gray") tt.pencolor("black") tt.speed(0) tt.penup() tt.goto(0,200) tt.pendown()
Here we are initializing our turtle object as tt. The background color is set to gray and the pencolor of the turtle is set to black. The speed of the turtle is initialized to 0. The position of the turtle is initialized to goto(0,200).
Penup() – Turtle doesn’t draw anything
Pendown()- Turtle begins drawing
Function for drawing a Vibrating Circle
#initialized the variables to zero forDis=0 dR=0 while(True): tt.forward(forDis) tt.right(dR) forDis+=3 dR+=1 if dR==210: break tt.hideturtle() turtle.done()
In this block of code, we are writing the function for drawing the vibrating circle. Here we have initialized the forDis(forward Distance) and dR(distance Right) variables to 0.
In the while loop, the condition is true, but the turtle will move forward distance set for forDis i.e after each iteration the forDis variable increases by 3. The turtle will move forward accordingly.
Similarly, the right angle variable dR is increased by 1 after each iteration.
In this, if the right angles i.e dR(distance Right) value becomes 210 then the loop will break. Hence the execution of the loop for the vibrating circle stops here and we get our desired output.
Complete Code to Draw Virus using Python Turtle
#Import Turtle import turtle tt=turtle.Turtle() turtle.bgcolor("gray")#Screen background color set to gray tt.pencolor("black")#Pencolor set to black tt.speed(0) tt.penup() tt.goto(0,200)#position of the turtle tt.pendown() #Intialization of variables forDis=0 dR=0 while(True): tt.forward(forDis) tt.right(dR) forDis+=3 # forDis increased by 3 on every iteration dR+=1# right angle distance increased by 1 on every iteration #If the distance for right angle becomes 210 the loop breaks if dR==210: break #Hide the turtle on completion of loop tt.hideturtle() #Completion of Turtle execution turtle.done()
Output

Thank you for reading the article.
Also Read:
- Bakery Management System in Python | Class 12 Project
- Filter List in Python | 10 methods
- Top 25 Pattern Programs in C++
- Currency Converter in C++
- SQLite | CRUD Operations in Python
- Number Guessing Game in C++
- Image background remover in Python
- C++ Project Structure
- Python | Check if a string is a palindrome or not without Recursion
- Python | Check if a number is an Armstrong Number or not using Recursion
- Python | Check if a number is an Armstrong Number or not without using Recursion
- Python | Shuffle a list using recursion
- Python | Shuffle a list without recursion
- Python | Implementing switch case using functions
- Python function to check whether a number is perfect or not
- Python | Find LCM using function
- Python | Find HCF using function
- Python | Convert the binary number to decimal without using library function
- Python | Create a basic operations calculator(+, -, /, and x), create a separate function for each operation
- Python | Detecting the number of local variables declared in a function
- Python | Making a chain of function decorators (bold italic underline etc)
- Python | Access function inside a function
- Event Management System Project in Python
- ATM machine program in C++
- Python | Create a function with a pass statement
- Python | Function to calculate the square root of a number
- Python | A function that calculates the power of a number
- Python | A function that accepts 2 integers and adds them and returns their sum
- Python | Function that takes a list of integers and returns the last integer
- Python | Return multiple values from a function