Draw sun using Turtle module in Python
Last Updated :
19 May, 2022
Prerequisite: Turtle Programming in Python
In this article, let’s learn how to draw the Sun using turtle in Python. Turtle is an inbuilt module in Python. It helps draw patterns by providing a screen and turtle (pen) as tools. To move the turtle as desired functions defined within the module like forward(), backward(), right(), left() etc. will be employed.
Approach:
- Import turtle module
- Set up a screen for turtle.
- Instantiate a turtle object.
- For making sun, define a method for circle along with radius and color.
- Define a function for creating sun rays.
Below is the implementation of the above approach.
Python3
import turtle
screen = turtle.Screen()
screen.bgcolor( "lightpink" )
y = turtle.Turtle()
def drawFourRays(t, length, radius):
for i in range ( 4 ):
t.penup()
t.forward(radius)
t.pendown()
t.forward(length)
t.penup()
t.backward(length + radius)
t.left( 90 )
y.penup()
y.goto( 85 , 110 )
y.fillcolor( "yellow" )
y.pendown()
y.begin_fill()
y.circle( 45 )
y.end_fill()
y.penup()
y.goto( 85 , 169 )
y.pendown()
drawFourRays(y, 85 , 54 )
y.right( 45 )
drawFourRays(y, 85 , 54 )
y.left( 45 )
turtle.done()
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...