}
h1, h2, h3 {
color: #55CDFC;
}
details {
background-color: #0B0C10;
padding: 10px;
border-radius: 5px;
margin: 10px 0;
}
pre {
background-color: #1F2833;
color: #E7E7E7;
padding: 10px;
border-radius: 5px;
}
code {
color: #F7A8B8;
}
Hello, young coder! 👋👾 Are you ready for an exciting journey to create a beautiful space scene using Python?
Your mission is to create a Space Adventure using Python's turtle module. You will draw a night sky filled with stars 🌠, a beautiful planet 🌍, and a spaceship 🛸 ready for a journey into the unknown!
Create a new Python file and call it `space_adventure.py`.
Import the turtle module like so:
Click for Hint
import turtle
# create a new turtle
space_turtle = turtle.Turtle()
We'll start by painting the canvas black, setting our turtle color to white, and creating a bunch of stars.
Click for Hint
# function to draw a star
def draw_star(turtle, size):
for _ in range(5):
turtle.forward(size)
turtle.right(144)
Can you use a loop to draw multiple stars at random places?
Now, let's draw a big, beautiful planet. You can choose the color!
Click for Hint
# function to draw a circle (for our planet)
def draw_planet(turtle, size, color):
turtle.penup()
turtle.goto(0, -size)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
turtle.circle(size)
turtle.end_fill()
Last but not least, let's draw a spaceship ready for take-off!
Click for Hint
def draw_spaceship(turtle, size):
turtle.penup()
turtle.goto(-size/2, -size*2)
turtle.color("grey")
turtle.pendown()
turtle.begin_fill()
for _ in range(2):
turtle.forward(size)
turtle.right(60)
turtle.forward(size)
turtle.right(120)
turtle.right(60)
turtle.forward(size)
turtle.end_fill()
Once you've drawn your stars, planet, and spaceship, it's time to admire your work! Complete your code with this line to hold the drawing screen open:
turtle.done()
Congrats, explorer! 🥳👏 You've just created a stunning space adventure using Python and Turtle!
Remember, this is your universe. You can add more stars, planets, or even a fleet of spaceships. Let your imagination run wild! 💭✨
Happy Coding! 🎉🎊