Creative graphics and interactive demos using Python Turtle
Learn Programming โข Create Art โข Build Interactive Applications
This repository showcases creative graphics projects and interactive applications built with Python's Turtle Graphics module. From drawing programs to generative art, these demos demonstrate how Turtle can be used for both learning programming fundamentals and creating impressive visual applications.
Perfect for beginners learning Python, educators teaching programming concepts, or anyone interested in creative coding!
Note: Demo applications were created with assistance from Google Gemini and Claude AI, and refined through experimentation.
|
|
Explore the creative possibilities of Python Turtle Graphics!
|
๐ Beginner Friendly Perfect for learning Python basics |
๐จ Visual Feedback See your code come to life instantly |
๐ง Built-in Module No external dependencies needed |
๐ Creative Expression Art, patterns, and animations |
- Python 3.x installed on your system
- Turtle module (included with Python standard library)
No additional installation required! ๐
-
Clone this repository:
git clone https://github.com/NguyenLe15325/Python-turtle.git cd Python-turtle -
Run any demo:
python paint.py # or python fractals.py -
Create and explore!
- Follow on-screen instructions for controls
- Experiment with colors and patterns
- Modify code to create your own designs
Progress through these demos to master Turtle Graphics:
1. ๐ข Basic Drawing (Simple shapes, lines)
โ Learn turtle movement and pen control
2. ๐ก Interactive Input (Click handling, keyboard events)
โ Understand event-driven programming
3. ๐ Complex Patterns (Loops, functions, recursion)
โ Create sophisticated designs
4. โซ Full Applications (Paint program, games)
โ Build complete interactive projects
5. ๐จ Your Masterpiece!
Create original artwork or tools
This interactive drawing application demonstrates the full capabilities of Python Turtle Graphics. It features a complete toolkit for creating digital artwork, including multiple drawing tools, color selection, and canvas managementโall built with Python's standard library!
-
๐๏ธ Multiple Drawing Tools
- Pencil โ Freehand drawing
- Brush โ Thicker lines
- Eraser โ Remove mistakes
- Fill tool โ Color regions
- Shapes โ Circles, rectangles, lines
-
๐จ Color System
- Color palette with preset colors
- Custom color picker
- RGB slider controls
- Recently used colors
-
๐ Drawing Controls
- Adjustable pen size (1-50 pixels)
- Pen up/down for disconnected lines
- Undo/redo functionality
- Clear canvas option
-
๐พ Save & Load
- Export drawings as PostScript (.eps)
- Save canvas state
- Load previous work
-
๐๏ธ User Interface
- Toolbar with tool icons
- Color palette display
- Size slider
- Status bar showing current tool and color
| Input | Action |
|---|---|
Left Click |
Draw with current tool |
Right Click |
Pick color from canvas |
Mouse Drag |
Continuous drawing |
1-9 |
Quick select pen size |
C |
Open color picker |
E |
Switch to eraser |
P |
Switch to pencil |
B |
Switch to brush |
U |
Undo last action |
R |
Redo |
Ctrl+S |
Save drawing |
Ctrl+Z |
Undo |
Ctrl+Y |
Redo |
Delete |
Clear canvas |
Core Components:
class PaintApp:
"""Main application class managing the paint program"""
def __init__(self):
self.screen = turtle.Screen()
self.canvas = turtle.Turtle()
self.current_tool = "pencil"
self.current_color = "black"
self.pen_size = 3
self.setup_ui()
def draw(self, x, y):
"""Handle drawing on canvas"""
if self.is_drawing:
self.canvas.goto(x, y)
def change_color(self, color):
"""Update drawing color"""
self.current_color = color
self.canvas.color(color)
def setup_ui(self):
"""Create toolbar and color palette"""
self.create_toolbar()
self.create_palette()
class ColorPalette:
"""Manages color selection interface"""
def __init__(self, x, y):
self.colors = [
"#000000", "#FFFFFF", "#FF0000", "#00FF00",
"#0000FF", "#FFFF00", "#FF00FF", "#00FFFF"
]
self.draw_palette(x, y)
def on_click(self, x, y):
"""Handle color selection clicks"""
selected = self.get_color_at(x, y)
return selected
class DrawingTool:
"""Base class for different drawing tools"""
def __init__(self, name, size, color):
self.name = name
self.size = size
self.color = color
def use(self, x, y):
"""Apply tool at coordinates"""
passEvent Handling:
def setup_events(app):
"""Configure mouse and keyboard events"""
screen = app.screen
# Mouse events
screen.onclick(app.on_click)
screen.onscreenclick(app.on_click, btn=1) # Left click
screen.onscreenclick(app.pick_color, btn=3) # Right click
# Keyboard shortcuts
screen.onkey(app.undo, "u")
screen.onkey(app.clear_canvas, "Delete")
screen.onkey(app.save, "s")
# Enable listening
screen.listen()- Event-Driven Programming โ Mouse clicks, drags, and keyboard input
- State Management โ Tracking current tool, color, and drawing state
- UI Design โ Creating toolbars, palettes, and interactive elements
- Object-Oriented Design โ Classes for tools, colors, and canvas management
- Graphics Programming โ Coordinate systems, transformations, and rendering
- File I/O โ Saving and loading drawings
- User Experience โ Undo/redo, visual feedback, and intuitive controls
Extend the paint program with these features:
- Layer System โ Multiple drawing layers with transparency
- Text Tool โ Add text with different fonts and sizes
- Stamps & Stickers โ Pre-made shapes and images
- Gradient Tool โ Smooth color transitions
- Symmetry Mode โ Mirror drawing for mandala effects
- Animation Export โ Record drawing process as video
- Pressure Sensitivity โ Variable line thickness (with tablet support)
- Filters & Effects โ Blur, brightness, contrast adjustments
- Grid & Guides โ Alignment helpers
- Custom Brushes โ Create brush patterns and textures
What you can create with the paint program:
- ๐ธ Mandalas โ Symmetrical geometric patterns
- ๐ Landscapes โ Simple scenic artwork
- ๐ญ Pixel Art โ Grid-based designs
- โ๏ธ Sketches โ Freehand drawings and doodles
- ๐ Diagrams โ Technical illustrations
- ๐ Abstract Art โ Colorful creative expressions
- Turtle Academy โ Interactive turtle graphics lessons
- Python for Kids - Turtle Graphics
- Trinket - Python Turtle Examples
Explore the beauty of recursive patterns with fractal drawing algorithms. Create stunning mathematical art including:
- Koch Snowflake โ Classic fractal pattern
- Sierpinski Triangle โ Self-similar triangular fractal
- Dragon Curve โ Space-filling dragon pattern
- Tree Fractals โ Recursive branching structures
Generate mesmerizing geometric patterns using loops and mathematical functions:
- Spirals โ Fibonacci, Archimedean, and golden spirals
- Rose Curves โ Mathematical rose patterns
- Star Polygons โ Multi-pointed star shapes
- Tessellations โ Repeating tile patterns
Simple games demonstrating game logic with Turtle:
- Snake Game โ Classic growing snake
- Pong โ Paddle and ball mechanics
- Maze Runner โ Navigate through generated mazes
- Catch Game โ Reflexes and timing
This project is licensed under the MIT License โ see the LICENSE file for details.
You're free to use, modify, and distribute this code for personal or commercial projects.
Python Turtle Graphics โ Built-in Python module for creative programming
The Python Community โ For tutorials, examples, and endless inspiration
Google Gemini & Claude AI โ AI assistance in generating and refining demo code
ezgif.com โ GIF editing and optimization tools
Creative Coding Community โ Artists and educators sharing their work
Nguyen Le โข @NguyenLe15325
๐ Star this repo โข ๐ Report Bug โข ๐ก Request Feature
