0% found this document useful (0 votes)
4 views13 pages

Python Turtle Graphics

The document provides an overview of Python Turtle Graphics, a built-in module for creating drawings and animations, inspired by the Logo programming language. It covers essential commands for setting up the canvas, basic movement, drawing shapes, colors, and creating functions for reusability. Additionally, it introduces advanced patterns, interactive features, and offers tips for effective usage, culminating in a challenge to create a fractal tree.

Uploaded by

ptejaswini787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Python Turtle Graphics

The document provides an overview of Python Turtle Graphics, a built-in module for creating drawings and animations, inspired by the Logo programming language. It covers essential commands for setting up the canvas, basic movement, drawing shapes, colors, and creating functions for reusability. Additionally, it introduces advanced patterns, interactive features, and offers tips for effective usage, culminating in a challenge to create a fractal tree.

Uploaded by

ptejaswini787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Python Turtle Graphics

Creative Programming with Visual Arts

TEJASWINI.P(24D21A12A7) 2025

DURGA(24D21A12A5)

IT B

PYTHON PPT………
What is Python Turtle?
Built-in Python Module Logo Language Legacy Visual Learning Tool
Pre-installed graphics library for Inspired by Logo programming Interactive way to learn
creating drawings and language from 1967, designed programming concepts through
animations for education graphics

Pen-Controlled Cursor
Turtle acts as a pen that moves around the screen, drawing lines
Setting Up Your Canvas
Essential Setup Commands

import turtle# Create screen and turtlewn =


turtle.Screen()t = turtle.Turtle()# Set screen size
and colorwn.setup(800, 600)wn.bgcolor("white")# Close
window when doneturtle.done()
Basic Movement Commands
Forward & Backward Turning

t.forward(100)t.backward(50)t.fd(100) # t.right(90)t.left(45)t.rt(90) #
shorthandt.bk(50) # shorthand shorthand t.lt(45) # shorthand

Positioning

t.goto(100, 50)t.setx(100)t.sety(50)t.home() # return to (0,0)


Drawing a Square
Step-by-Step Approach

import turtlet = turtle.Turtle()# Draw square -


repeat 4 timesfor i in range(4): t.forward(100)
t.right(90)turtle.done()

Key Concept: Move forward, turn 90°, repeat 4 times


More Shapes with Loops
Triangle Hexagon

for i in range(3): t.forward(100) for i in range(6): t.forward(100)


t.right(120) t.right(60)

Pentagon Any Regular Polygon

for i in range(5): t.forward(100) sides = 8angle = 360 / sidesfor i in


t.right(72) range(sides): t.forward(100) t.right(angle)
Colors and Styling
Pen Colors Fill Colors Pen Properties

t.pencolor("red")t.penco t.fillcolor("blue")t.beg t.pensize(5)t.speed(10)t


lor("#FF5733")t.pencolor in_fill()# draw .penup() # lift
(255, 0, 0) shapet.end_fill() pent.pendown() # put pen
down
Creating Functions for Reusability
Smart Programming with Functions

def draw_square(size): for i in range(4): t.forward(size) t.right(90)def draw_polygon(sides, size): angle =


360 / sides for i in range(sides): t.forward(size) t.right(angle)# Use the
functionsdraw_square(100)t.penup()t.goto(200, 0)t.pendown()draw_polygon(6, 80)
Advanced Patterns: Spirals
Creating Beautiful Spirals

import turtlet = turtle.Turtle()t.speed(0) # fastest# Square


spiralfor i in range(100): t.forward(i * 2) t.right(90)#
Colorful spiralcolors = ['red', 'blue', 'green',
'yellow']for i in range(100): t.pencolor(colors[i % 4])
t.forward(i * 3) t.right(91)
Interactive Features

Mouse Events Keyboard Control Animation

def click_handler(x, y): def move_up(): def animate(): t.right(10)


t.goto(x, t.setheading(90) t.forward(5)
y)wn.onclick(click_handler) t.forward(20)wn.onkey(move_ wn.ontimer(animate,
up, "Up")wn.listen() 50)animate()
Pro Tips and Tricks
Speed Control
Use t.speed(0) for fastest drawing, t.speed(1) for slowest

Hide Turtle
Use t.hideturtle() to hide cursor after drawing

Screen Updates
Use wn.tracer(0) and wn.update() for smooth animations

Save Your Art


Use wn.getcanvas().postscript(file="myart.eps") to save
Challenge: Fractal Tree
Recursive Programming

def draw_tree(branch_length): if branch_length > 5:


t.forward(branch_length) t.right(20)
draw_tree(branch_length - 15) t.left(40)
draw_tree(branch_length - 15) t.right(20)
t.backward(branch_length)t.left(90)draw_tree(100)
Next Steps in Your Journey

Explore Art Projects Build Simple Games Data Visualization


Create mandalas, geometric Snake, Pong, or maze games using Create charts and graphs with turtle
patterns, and digital art turtle graphics drawing

Learn Advanced Python


Move to matplotlib, pygame, or web
development

Remember: Turtle graphics is just the beginning. Every line of code you write builds your programming confidence!

You might also like