Code:
import turtle
import time
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#10152b")
t = turtle.Turtle()
t.hideturtle()
t.speed(3)
t.width(3)
# -------------------------
# Filled Shape
# -------------------------
def shape(points, fill):
t.color(fill)
t.fillcolor(fill)
t.penup()
t.goto(*points[0])
t.pendown()
t.begin_fill()
for p in points[1:]:
t.goto(*p)
time.sleep(0.12)
t.goto(*points[0])
t.end_fill()
time.sleep(0.5)
# ๐ House
shape(
[(-120, -210), (120, -210),
(100, 50), (-100, 50)],
"#ffe0a3"
)
# ๐ Roof
shape(
[(-170, 20), (170, 20),
(125, 115), (70, 170),
(0, 195), (-70, 170),
(-125, 115)],
"#ff3d71"
)
# ✨ Roof spots
for x, y, r in [
(-90, 110, 18),
(-25, 155, 13),
(45, 125, 20),
(100, 75, 12)
]:
t.penup()
t.goto(x, y)
t.dot(r * 2, "#fff4d6")
screen.update()
time.sleep(0.35)
# ๐ช Door
shape(
[(-35, -210), (35, -210),
(35, -80), (-35, -80)],
"#7b3f20"
)
# ๐ช Windows
for x in [-75, 75]:
t.penup()
t.goto(x, -20)
t.dot(55, "#65e6ff")
screen.update()
time.sleep(0.4)
t.dot(40, "#17294f")
screen.update()
time.sleep(0.4)
# ⭐ Stars
stars = [
(-270, 220),
(-210, 280),
(220, 250),
(275, 180),
(180, 330),
(-300, 100)
]
for x, y in stars:
t.penup()
t.goto(x, y)
t.color("#ffe600")
t.write(
"✦",
align="center",
font=("Arial", 22, "bold")
)
screen.update()
time.sleep(0.3)
# ๐ฑ Grass
t.color("#4cff88")
t.width(4)
for x in range(-300, 301, 35):
t.penup()
t.goto(x, -220)
t.setheading(75)
t.pendown()
t.forward(18)
screen.update()
time.sleep(0.1)
# ๐ Final pause
time.sleep(3)
turtle.done()
Explanation:
1. Import Libraries
import turtle
import time
turtle → Used for drawing.
time → Adds animation delays.
2. Create the Screen
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#10152b")
Creates a 700 × 700 window.
Sets a dark blue background.
3. Configure the Turtle
t = turtle.Turtle()
t.hideturtle()
t.speed(3)
t.width(3)
Creates the turtle.
Hides the turtle cursor.
Sets drawing speed to 3.
Sets line width to 3.
๐จ 4. Create the Shape Function
def shape(points, fill):
Defines a reusable function for drawing filled shapes.
points → Coordinates of the shape.
fill → Fill color.
t.color(fill)
t.fillcolor(fill)
Sets the outline and fill colors.
t.penup()
t.goto(*points[0])
t.pendown()
Moves to the first point without drawing.
Starts drawing from there.
t.begin_fill()
Starts filling the shape.
for p in points[1:]:
t.goto(*p)
time.sleep(0.12)
Connects all given points.
Adds a small delay for animation.
t.goto(*points[0])
t.end_fill()
Returns to the first point.
Completes and fills the shape.
time.sleep(0.5)
Pauses briefly before the next object.
๐ 5. Draw the House
shape(
[(-120, -210), (120, -210),
(100, 50), (-100, 50)],
"#ffe0a3"
)
Creates the main rectangular house.
Uses a warm light-yellow color.
๐ 6. Draw the Mushroom Roof
shape(
[(-170, 20), (170, 20),
(125, 115), (70, 170),
(0, 195), (-70, 170),
(-125, 115)],
"#ff3d71"
)
Creates the curved mushroom-style roof.
Uses a bright pink-red color.
✨ 7. Add Roof Spots
for x, y, r in [
(-90, 110, 18),
(-25, 155, 13),
(45, 125, 20),
(100, 75, 12)
]:
Defines the position and size of four roof spots.
t.penup()
t.goto(x, y)
Moves to each spot location.
t.dot(r * 2, "#fff4d6")
Draws a light-colored circular spot.
screen.update()
time.sleep(0.35)
Updates the screen.
Creates a visible drawing animation.
๐ช 8. Draw the Door
shape(
[(-35, -210), (35, -210),
(35, -80), (-35, -80)],
"#7b3f20"
)
Creates a rectangular door.
Uses a brown color.
๐ช 9. Draw the Windows
for x in [-75, 75]:
Creates two windows.
Uses two different X positions.
t.penup()
t.goto(x, -20)
Moves to the window position.
t.dot(55, "#65e6ff")
Draws a large glowing cyan window.
t.dot(40, "#17294f")
Adds a smaller dark circle inside.
Creates a window-frame/depth effect.
screen.update()
time.sleep(0.4)
Animates each window.
⭐ 10. Add Stars
stars = [
(-270, 220),
(-210, 280),
(220, 250),
(275, 180),
(180, 330),
(-300, 100)
]
Stores the positions of six stars.
for x, y in stars:
Loops through each star position.
t.penup()
t.goto(x, y)
Moves to the star's position.
t.color("#ffe600")
Sets the star color to yellow.
t.write(
"✦",
align="center",
font=("Arial", 22, "bold")
)
Writes a star symbol.
Centers it at the selected position.
Uses a bold Arial font.
๐ฑ 11. Create the Grass
t.color("#4cff88")
t.width(4)
Sets a bright green color.
Makes the grass lines thicker.
for x in range(-300, 301, 35):
Creates grass at regular intervals.
t.penup()
t.goto(x, -220)
t.setheading(75)
Moves to the ground position.
Tilts the turtle upward.
t.pendown()
t.forward(18)
Draws a short grass blade.
screen.update()
time.sleep(0.1)
Updates the screen.
Creates a small animation delay.
๐ 12. Final Pause
time.sleep(3)
Keeps the completed scene visible for 3 seconds.
13. Finish
turtle.done()
Keeps the Turtle window open.
Ends the program.

0 Comments:
Post a Comment