Draw Concentric Circles with VIBGYOR Using Turtle in Python
Last Updated :
20 Oct, 2020
Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc.
To draw Concentric VIBGYOR :
Following steps are used :
- Importing turtle module
- Set a screen
- Make Turtle object
- Define a method for circle with dynamic radius and colour.
- Write text by setting turtle object at required position.
Below is the implementation :
Python3
import turtle
sc = turtle.Screen()
sc.bgcolor( 'black' )
pen = turtle.Turtle()
pen.width( 4 )
def circle(col, rad, val):
pen.color(col)
pen.circle(rad)
pen.up()
pen.setpos( 0 , val)
pen.down()
def text():
pen.color( 'white' )
pen.up()
pen.setpos( - 100 , 140 )
pen.down()
pen.write( "Concentric VIBGYOR" ,
font = ( "Verdana" , 15 ))
pen.up()
pen.setpos( - 82 , - 188 )
pen.down()
pen.write( "Using Turtle Graphics" ,
font = ( "Verdana" , 12 ))
pen.hideturtle()
if __name__ = = "__main__" :
col = [ 'violet' , 'indigo' , 'blue' ,
'green' , 'yellow' , 'orange' ,
'red' ]
for i in range ( 7 ):
circle(col[i], - 20 * (i + 1 ), 20 * (i + 1 ))
text()
|
Output :
Concentric Vibgyor
Share your thoughts in the comments
Please Login to comment...