Draw Concentric Circles with VIBGYOR Using Turtle in Python
Prerequisite: Turtle Programming Basics
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 package import turtle # Screen object sc = turtle.Screen() # Screen background color sc.bgcolor( 'black' ) # turtle object pen = turtle.Turtle() # turtle width pen.width( 4 ) # function to draw a circle of # rad radius and col color def circle(col, rad, val): pen.color(col) pen.circle(rad) pen.up() # set position for space pen.setpos( 0 , val) pen.down() # function to write text # by setting positions 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() # Driver code if __name__ = = "__main__" : # VIBGYOR color list col = [ 'violet' , 'indigo' , 'blue' , 'green' , 'yellow' , 'orange' , 'red' ] # 7 Concentric circles for i in range ( 7 ): # function call circle(col[i], - 20 * (i + 1 ), 20 * (i + 1 )) # function call text() |