Sunday, 27 September 2026

Python Turtle The Magical Mushroom House

 



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

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (346) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (14) C (78) C# (12) C++ (83) cloud (1) Course (93) Coursera (305) Cybersecurity (36) data (10) Data Analysis (47) Data Analytics (31) data management (16) Data Science (434) Data Strucures (19) Deep Learning (222) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Generative AI (78) Git (13) Google (55) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (407) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (35) Python (1377) Python Coding Challenge (1257) Python Library (11) Python Mathematics (19) Python Mistakes (51) Python Pattern Challenge (13) Python Quiz (644) Python Tips (112) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (21) SQL (55) Udemy (22) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)