/Python-turtle

This is a Python turtle demo repository github that contains examples and demonstrations using Python's turtle graphics module.

Primary LanguagePythonMIT LicenseMIT

๐Ÿข Python Turtle Graphics

Python Turtle Graphics License Demos

Creative graphics and interactive demos using Python Turtle

Learn Programming โ€ข Create Art โ€ข Build Interactive Applications


๐Ÿš€ Project Overview

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.


๐ŸŽจ Demo Collection

๐Ÿ–Œ๏ธ Creative Tools

  • Paint Program โ€” Full-featured drawing application
  • Pattern Generator โ€” Create geometric designs
  • Fractal Explorer โ€” Recursive art patterns

๐ŸŽฎ Interactive Demos

  • Games โ€” Simple turtle-based games
  • Animations โ€” Moving graphics and effects
  • Educational Tools โ€” Visual learning aids

Explore the creative possibilities of Python Turtle Graphics!


๐Ÿงฉ Why Python Turtle?

๐Ÿ“š
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

๐Ÿ›  Getting Started

Prerequisites

  • Python 3.x installed on your system
  • Turtle module (included with Python standard library)

No additional installation required! ๐ŸŽ‰

Running a Demo

  1. Clone this repository:

    git clone https://github.com/NguyenLe15325/Python-turtle.git
    cd Python-turtle
  2. Run any demo:

    python paint.py
    # or
    python fractals.py
  3. Create and explore!

    • Follow on-screen instructions for controls
    • Experiment with colors and patterns
    • Modify code to create your own designs

๐ŸŽฏ Learning Path

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


โญ Featured Project: Paint Application

๐ŸŽจ Full-Featured Drawing Program

A complete paint application built entirely with Python Turtle!

Paint Application Demo

๐ŸŽฏ About the Paint Program

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!

โœจ Key Features

  • ๐Ÿ–Œ๏ธ 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

๐ŸŽฎ Controls

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

๐Ÿ”ง Technical Implementation

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"""
        pass

Event 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()

๐ŸŽ“ What You'll Learn

  • 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

๐Ÿ’ก Enhancement Ideas

Extend the paint program with these features:

  1. Layer System โ€” Multiple drawing layers with transparency
  2. Text Tool โ€” Add text with different fonts and sizes
  3. Stamps & Stickers โ€” Pre-made shapes and images
  4. Gradient Tool โ€” Smooth color transitions
  5. Symmetry Mode โ€” Mirror drawing for mandala effects
  6. Animation Export โ€” Record drawing process as video
  7. Pressure Sensitivity โ€” Variable line thickness (with tablet support)
  8. Filters & Effects โ€” Blur, brightness, contrast adjustments
  9. Grid & Guides โ€” Alignment helpers
  10. Custom Brushes โ€” Create brush patterns and textures

๐ŸŽจ Example Drawings

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

๐Ÿ“– Python Turtle Resources

๐Ÿ“š Official Documentation

๐ŸŽฅ Video Tutorials

๐Ÿ“ Learning Resources


๐ŸŽจ More Demo Highlights

๐ŸŒ€ Fractal Generator

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

๐ŸŽฏ Pattern Designer

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

๐ŸŽฎ Interactive Games

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

๐Ÿ“œ License

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.


๐Ÿค Acknowledgements

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


๐Ÿ“ง Contact & Links

Nguyen Le โ€ข @NguyenLe15325

๐ŸŒŸ Star this repo โ€ข ๐Ÿ› Report Bug โ€ข ๐Ÿ’ก Request Feature


๐Ÿข Have fun creating art and learning Python with Turtle Graphics!

Made with โค๏ธ and Python

โญ If you find this helpful, consider starring the repository! โญ