Draw Clock Design using Turtle in Python
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 Clock Design :
Following steps are used :
- Import turtle.
- Create Screen object and set Screen configuration.
- Create Turtle object and set its position and speed.
- Draw a dashed line and print number in circular shape.
- Draw center and fill color black in it
- Write “GFG” and “CLOCK” at required position.
Below is the implementation:
Python3
import turtle
screen = turtle.Screen()
screen.setup( 500 , 500 )
clk = turtle.Turtle()
clk.color( 'Green' )
clk.width( 4 )
def draw_hour_hand():
clk.penup()
clk.home()
clk.right( 90 )
clk.pendown()
clk.forward( 100 )
val = 0
for i in range ( 12 ):
val + = 1
clk.penup()
clk.setheading( - 30 * (i + 3 ) + 75 )
clk.forward( 22 )
clk.pendown()
clk.forward( 15 )
clk.penup()
clk.forward( 20 )
clk.write( str (val), align = "center" ,
font = ( "Arial" ,
12 , "normal" ))
clk.setpos( 2 , - 112 )
clk.pendown()
clk.width( 2 )
clk.fillcolor( 'Green' )
clk.begin_fill()
clk.circle( 5 )
clk.end_fill()
clk.penup()
draw_hour_hand()
clk.setpos( - 20 , - 64 )
clk.pendown()
clk.penup()
clk.setpos( - 30 , - 170 )
clk.pendown()
clk.write( ' GfG Clock' , font = ( "Arial" , 14 ,
"normal" ))
clk.hideturtle()
turtle.done()
|
Output:
Last Updated :
26 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...