VOOZH about

URL: https://www.geeksforgeeks.org/python/draw-starry-sky-with-moon-using-turtle-in-python/

โ‡ฑ Draw Starry Sky with Moon using Turtle in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Draw Starry Sky with Moon using Turtle in Python

Last Updated : 23 Jul, 2025

Prerequisites: Turtle Programming in Python

In Python, Turtle is an in-built library that provides us to draw different patterns, shapes or anything we want but for that, we have to be aware of the uses of different functions provided by Turtle library.

In this article we are going to learn how to draw the Starry Sky. Maybe this article went long but after reading the whole article you get to understand each and every step easily.

For that, we are using the turtle library and random module for generating random positions to draw to the stars.

Methods we are using to draw Starry Sky are listed below.

METHODPARAMETER DESCRIPTION
Turtle()None It creates and returns a new turtle object.
bgcolorcolor namefills the color in the background of the window
circle()radius, extent, stepsDraw a circle with given radius.
title()nameGives name to the turtle window
forward() / fd()amountIt moves the turtle forward by the specified amount.
Screen()NoneAfter passing this method turtle screen will be active
speedvalueDecides the speed of the pen
up()NonePicks up the turtleโ€™s Pen.
down()NonePicks down the turtleโ€™s Pen.
left()angleIt turns the turtle counter clockwise.
right()angleIt turns the turtle clockwise.
goto() x, yIt moves the turtle to position x, y.
begin_fill()NoneCall just before drawing a shape to be filled. Equivalent to fill(True).
end_fill()NoneFill the shape drawn after the last call to begin_fill(). Equivalent to fill(False).
hideturtle()NoneHides the turtle after finishing the drawing.
exitonclick()NoneOn clicking exit the turtle screen.
randintstart, end valueGenerates random values with in the given range.

Our Starry Sky is made up of many Stars and with one moon which is in the shape of a Circle. So, we have to learn first how to draw the Stars and Circle.

Let's first learn how to draw the star through our code.

Output:

๐Ÿ‘ Image

In the above code, we run the for loop from range 0 to 5 because as we all knew star has 5 edges and the angle between two edges will be 144 degrees to make the perfect star that's what we are doing in the line t.right(144) we are moving the turtles head at the angle 144 degrees and the line t.fd(200) decides the size of our star (smaller the value = smaller the star)

Now, we are going to learn how to draw the Circle through our code.

Output:

๐Ÿ‘ Image

In the above code, for making a circle we are using the circle function provided by the turtle library, only we had passed the parameter 100 which defines the radius of the circle. After running our code we get our circle.

So, finally, we had learned how to draw the star and the circle.

Now we are going to draw our Starry Sky.

Output:

๐Ÿ‘ Image
Starry Sky

๐Ÿ‘ Image

In the above code you will be understand after reading the comments before every line of code you get the crystal clear idea that how our code works and drawing the Starry stars.

Comment
Article Tags:
Article Tags: