Skip to content

Comprehensive number pattern generator using Python. Create pyramid patterns, number sequences, and mathematical patterns. Features multiple pattern types with customizable parameters. Perfect for learning Python loops, conditional statements, and algorithmic thinking.

Notifications You must be signed in to change notification settings

rskworld/python-pattern-generator

Repository files navigation

Python Number Pattern Generator πŸ”’

Author: Molla Samser (Founder, RSK World)
Designer & Tester: Rima Khatun
Website: https://rskworld.in
Email: hello@rskworld.in, support@rskworld.in
Phone: +91 93305 39277
Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India - 713147
Year: 2026

πŸ“– Description

A comprehensive number pattern generator using Python with an intuitive GUI interface. This application allows users to create various mathematical patterns, sequences, and geometric shapes using numbers. Perfect for learning Python loops, conditional statements, and algorithmic thinking.

✨ Features

  • 22 Pattern Types: Choose from 22 different patterns including fractals, cellular automata, and advanced mathematical patterns
  • Advanced Algorithms: Sierpinski triangles, Mandelbrot sets, Hilbert curves, Dragon curves, Koch snowflakes
  • Web Interface: Full Flask web application with modern UI and API endpoints
  • Multiple Export Formats: Text, JSON, PNG images, and SVG vector graphics
  • Animation System: Step-by-step pattern generation animations
  • Comprehensive API: REST API for programmatic pattern generation
  • Pattern Comparison: Advanced diff tools and similarity analysis
  • Configuration System: Customizable settings and themes
  • Unit Testing: Complete test suite with performance benchmarks
  • Theme Support: Multiple themes (Default, Dark, Light, Color) with syntax highlighting
  • Real-time Features: Live search, analysis, and validation

🎯 Pattern Types (22 Total)

Basic Patterns

  1. Pyramid Pattern - Classic pyramid shape with numbers
  2. Reverse Pyramid - Inverted pyramid pattern
  3. Number Triangle - Right-angled triangle with numbers
  4. Number Square - Grid pattern with sequential numbers
  5. Diamond Pattern - Diamond shape with numbers
  6. Hourglass Pattern - Hourglass shape using numbers

Mathematical Patterns

  1. Pascal's Triangle - Binomial coefficients triangle
  2. Floyd's Triangle - Sequential numbers in triangular arrangement
  3. Fibonacci Triangle - Fibonacci sequence triangle
  4. Multiplication Table - Math multiplication table
  5. Magic Square - Mathematical magic square (odd sizes only)
  6. Prime Numbers - Grid displaying prime numbers
  7. Number Spiral - Spiral arrangement of numbers

Advanced/Fractal Patterns

  1. Sierpinski Triangle - Fractal triangle pattern
  2. Mandelbrot Set - Mandelbrot set visualization
  3. Hilbert Curve - Space-filling Hilbert curve
  4. Dragon Curve - Dragon curve fractal
  5. Koch Snowflake - Koch snowflake fractal
  6. Cellular Automaton - Wolfram cellular automaton
  7. Binary Tree - Binary tree visualization

Special Features

  • ⭐ Animation Support: Step-by-step generation for most patterns
  • 🎨 Syntax Highlighting: Color-coded numbers and symbols in exports
  • πŸ“Š Advanced Analysis: Complexity metrics and pattern statistics

πŸš€ Getting Started

Prerequisites

  • Python 3.6 or higher
  • Tkinter (usually comes pre-installed with Python)

Installation

  1. Clone or download the project
  2. Navigate to the project directory
  3. Run the main application:
python main.py

Usage

Desktop Application

python main.py

Web Interface

python web_app.py
# Visit http://localhost:5000

Command-line Demo

python demo.py

API Usage

from api import generate_pattern
pattern = generate_pattern('pyramid', 5, 1)

Interfaces

1. Desktop GUI (main.py)

  • 22 Pattern Types with real-time search and filtering
  • Advanced Analysis with detailed statistics and complexity metrics
  • Multiple Export Formats (Text, PNG, JSON)
  • Theme Support (Default, Dark, Light, Color)
  • Animation System for step-by-step pattern generation
  • Pattern Comparison tools with diff visualization

2. Web Application (web_app.py)

  • Modern Bootstrap UI with responsive design
  • REST API endpoints for programmatic access
  • Real-time Generation with AJAX
  • Interactive Features (search, analysis, export)
  • API Documentation accessible via web interface

3. Command-line Tools

  • Demo Interface (demo.py) - Interactive pattern exploration
  • API Client (api.py) - Programmatic pattern generation
  • Test Suite (test_patterns.py) - Comprehensive testing
  • Configuration (config.py) - Settings management

Advanced Features

Analysis & Comparison

  • Detailed Statistics: Lines, characters, numbers, complexity metrics
  • Pattern Comparison: Side-by-side diff and similarity scoring
  • Performance Benchmarking: Speed tests across pattern types
  • Complexity Analysis: Mathematical complexity evaluation

Export & Visualization

  • Multiple Formats: Text, JSON, PNG, SVG, PDF (planned)
  • Animated SVG: Step-by-step pattern evolution
  • Syntax Highlighting: Color-coded exports with themes
  • Batch Export: Multiple patterns at once

Animation & Interactivity

  • Step-by-step Animation: Watch patterns build incrementally
  • Interactive Controls: Real-time parameter adjustment
  • Progress Tracking: Visual feedback during generation
  • Speed Control: Adjustable animation timing

API & Integration

  • RESTful API: Full programmatic access
  • Batch Processing: Generate multiple patterns
  • Error Handling: Comprehensive validation and error reporting
  • Metadata Support: Rich pattern information and statistics

πŸ“Έ Screenshots

The application features a clean, modern interface with:

  • Header with project information
  • Left panel for controls and pattern selection
  • Right panel for pattern output display
  • Status bar for user feedback

πŸ› οΈ Technical Details

Dependencies

  • tkinter: GUI framework (built-in with Python)
  • datetime: For timestamp generation
  • os: For file operations
  • typing: For type hints (built-in with Python 3.5+)
  • math: For mathematical calculations (built-in with Python)
  • pillow (optional): For PNG image export (pip install pillow)

Project Structure

python-pattern-generator/
β”œβ”€β”€ main.py                    # Desktop GUI application
β”œβ”€β”€ patterns.py               # Pattern generation algorithms
β”œβ”€β”€ demo.py                   # Command-line demo interface
β”œβ”€β”€ web_app.py               # Flask web application
β”œβ”€β”€ api.py                    # REST API for programmatic access
β”œβ”€β”€ animation.py             # Pattern animation system
β”œβ”€β”€ svg_export.py           # SVG/PDF export functionality
β”œβ”€β”€ pattern_comparison.py   # Pattern comparison and analysis tools
β”œβ”€β”€ config.py               # Configuration management
β”œβ”€β”€ test_patterns.py        # Comprehensive unit tests
β”œβ”€β”€ index.html             # Static web interface
β”œβ”€β”€ README.md              # Project documentation
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ templates/             # Flask HTML templates
β”‚   └── index.html
└── static/               # Static web assets
    β”œβ”€β”€ css/
    β”‚   └── style.css
    └── js/
        └── app.js

Code Architecture

  • PatternGenerator Class: Main application class
  • Pattern Methods: Individual methods for each pattern type
  • GUI Components: Tkinter widgets for user interface
  • Export Functionality: File saving capabilities

πŸŽ“ Educational Value

This project is excellent for learning:

  • Python Loops: For loops, while loops, nested loops
  • Conditional Statements: If-else logic for pattern generation
  • Algorithmic Thinking: Problem-solving and pattern recognition
  • GUI Development: Tkinter interface design
  • File Operations: Reading and writing files
  • Mathematical Concepts: Prime numbers, Pascal's triangle, etc.

πŸ”§ Customization

You can easily add new patterns by:

  1. Adding a new pattern method to the PatternGenerator class
  2. Updating the pattern selection list in setup_ui()
  3. Adding the pattern to the generate_pattern() method

Example of adding a new pattern:

def generate_custom_pattern(self, size, start_num):
    """Generate custom pattern"""
    pattern = []
    # Your pattern logic here
    return "\n".join(pattern)

πŸ“ Examples

Pyramid Pattern (Size: 5, Start: 1)

        1
      1 2
    1 2 3
  1 2 3 4
1 2 3 4 5

Floyd's Triangle (Size: 4)

  1  2  3
  4  5  6
  7  8  9
 10 11 12

Number Spiral (Size: 3)

  1  2  3
  8  9  4
  7  6  5

🀝 Contributing

Contributions are welcome! Please feel free to submit issues, enhancement requests, or pull requests.

πŸ“„ License

This project is part of RSK World's educational resources. Content is used for educational purposes only.

πŸ“ž Contact

🌐 About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Development Categories

  • Game Development
  • Web Development
  • Mobile Development
  • Software Development
  • Development Tools

Β© 2026 RSK World. All rights reserved.
Developed with ❀️ for educational purposes

About

Comprehensive number pattern generator using Python. Create pyramid patterns, number sequences, and mathematical patterns. Features multiple pattern types with customizable parameters. Perfect for learning Python loops, conditional statements, and algorithmic thinking.

Resources

Stars

Watchers

Forks

Packages

No packages published