Tuesday, 22 September 2026

๐ŸŒŸ Python Turtle: A Smile Made with Code

 



Code:

import turtle import time screen = turtle.Screen() screen.setup(600, 600) screen.bgcolor("#050510") t = turtle.Turtle() t.hideturtle() t.speed(0) # Face t.penup() t.goto(0, -180) t.color("#ffd600") t.fillcolor("#ffd600") t.begin_fill() t.circle(180) t.end_fill() screen.update() time.sleep(0.3) # Eyes for x in [-65, 65]: t.penup() t.goto(x, 45) t.dot(35, "#151515") screen.update() time.sleep(0.2) # Smile t.penup() t.goto(-85, -30) t.setheading(-60) t.color("#151515") t.width(10) t.pendown() for _ in range(60): t.forward(3) t.left(2) screen.update() time.sleep(0.015) # Small highlights for x in [-58, 72]: t.penup() t.goto(x, 55) t.dot(8, "white") 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(600, 600)
screen.bgcolor("#050510")
Creates the Turtle window.
Sets the size to 600 × 600.
Gives it a dark background.

3. Create the Turtle
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
Creates the drawing turtle.
Hides the turtle cursor.
Sets the fastest drawing speed.

4. Draw the Face
t.penup()
t.goto(0, -180)
Lifts the pen.
Moves to the starting position.
t.color("#ffd600")
t.fillcolor("#ffd600")
Sets the outline color.
Sets the face fill color to yellow.
t.begin_fill()
t.circle(180)
t.end_fill()
Starts filling the shape.
Draws a circle with radius 180.
Fills it with yellow.

5. Animate the Face
screen.update()
time.sleep(0.3)
Updates the screen.
Pauses briefly.

6. Draw the Eyes
for x in [-65, 65]:
Loops through two X positions.
Creates the left and right eyes.
t.penup()
t.goto(x, 45)
Moves to each eye position without drawing.
t.dot(35, "#151515")
Draws a dark circular eye.
screen.update()
time.sleep(0.2)
Updates the screen.
Adds an animation delay.

7. Draw the Smile
t.penup()
t.goto(-85, -30)
Moves to the starting point of the smile.
t.setheading(-60)
Sets the initial drawing direction.
t.color("#151515")
t.width(10)
t.pendown()
Sets a dark color.
Makes the smile thick.
Starts drawing.

8. Create the Curved Smile
for _ in range(60):
Repeats the drawing movement 60 times.
t.forward(3)
t.left(2)
Moves forward.
Turns slightly left.
Together, these create the curved smile.
screen.update()
time.sleep(0.015)
Updates the animation.
Adds a tiny delay.

9. Add Eye Highlights
for x in [-58, 72]:
Selects positions for both eye highlights.
t.penup()
t.goto(x, 55)
Moves to each highlight position.
t.dot(8, "white")
Adds a small white dot.
Creates a shiny eye effect.

10. Finish
turtle.done()
Keeps the Turtle window open.
Ends the drawing.












0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (345) 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 (433) Data Strucures (18) Deep Learning (220) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Generative AI (77) 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 (404) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (35) Python (1376) Python Coding Challenge (1246) Python Library (6) Python Mathematics (17) Python Mistakes (51) Python Pattern Challenge (8) Python Quiz (638) 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)