help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
python-pattern-generator
RSK World
python-pattern-generator
Python Number Pattern Generator - 22 Pattern Types + Fractals + Mathematical Algorithms + GUI & Web Interface + REST API + Educational Design
python-pattern-generator
  • __pycache__
  • static
  • templates
  • .gitignore1.6 KB
  • README.md9.7 KB
  • animation.py14.3 KB
  • api.py19.9 KB
  • config.py14 KB
  • demo.py9.3 KB
  • index.html10.1 KB
  • main.py30.9 KB
  • pattern_comparison.py15.4 KB
  • patterns.py23 KB
  • push_to_github.bat3.9 KB
  • requirements.txt1 KB
  • svg_export.py13.4 KB
  • test_gui.py2.2 KB
  • test_patterns.py13.7 KB
  • web_app.py13.6 KB
demo.py
demo.py
Raw Download
Find: Go to:
"""
Demo Script for 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: Command-line demo of pattern generation
"""

from patterns import PatternAlgorithms, PatternUtils
import time


def print_separator(title):
    """Print a formatted separator with title"""
    print("\n" + "=" * 60)
    print(f" {title} ".center(60, "="))
    print("=" * 60)


def demo_pattern(name, pattern_func, size, start_num=1):
    """Demonstrate a single pattern"""
    print(f"\n{name} (Size: {size}, Start: {start_num}):")
    print("-" * 40)
    
    start_time = time.time()
    
    if name == "Pascal's Triangle" or name == "Prime Numbers":
        pattern = pattern_func(size)
    else:
        pattern = pattern_func(size, start_num)
    
    end_time = time.time()
    
    print(pattern)
    
    # Show statistics
    stats = PatternUtils.get_pattern_stats(pattern)
    print(f"\nStatistics:")
    print(f"  Lines: {stats['lines']}")
    print(f"  Characters: {stats['characters']}")
    print(f"  Numbers: {stats['numbers']}")
    print(f"  Generation time: {(end_time - start_time)*1000:.2f} ms")


def interactive_demo():
    """Interactive demo where user can choose patterns"""
    algorithms = PatternAlgorithms()
    
    patterns = [
        ("Pyramid", algorithms.pyramid),
        ("Reverse Pyramid", algorithms.reverse_pyramid),
        ("Triangle", algorithms.triangle),
        ("Pascal's Triangle", algorithms.pascal_triangle),
        ("Floyd's Triangle", algorithms.floyd_triangle),
        ("Square", algorithms.square),
        ("Diamond", algorithms.diamond),
        ("Hourglass", algorithms.hourglass),
        ("Spiral", algorithms.spiral),
        ("Prime Numbers", algorithms.prime_numbers),
        ("Fibonacci Triangle", algorithms.fibonacci_triangle),
        ("Multiplication Table", algorithms.multiplication_table),
        ("Magic Square", algorithms.magic_square),
        ("Sierpinski Triangle", algorithms.sierpinski_triangle),
        ("Mandelbrot Set", algorithms.mandelbrot_set),
        ("Hilbert Curve", algorithms.hilbert_curve),
        ("Dragon Curve", algorithms.dragon_curve),
        ("Koch Snowflake", algorithms.koch_snowflake),
        ("Cellular Automaton", algorithms.cellular_automaton),
        ("Binary Tree", algorithms.binary_tree),
    ]
    
    print_separator("Python Number Pattern Generator - Interactive Demo")
    print("Developed by Molla Samser (RSK World)")
    print("Designed by Rima Khatun")
    print("Website: https://rskworld.in")
    print("© 2026 RSK World. All rights reserved.")
    
    while True:
        print("\nAvailable Patterns:")
        for i, (name, _) in enumerate(patterns, 1):
            print(f"{i:2d}. {name}")
        print(" 0. Exit")
        
        try:
            choice = input("\nEnter your choice (0-10): ").strip()
            choice_num = int(choice)
            
            if choice_num == 0:
                print("\nThank you for using Python Number Pattern Generator!")
                break
            elif 1 <= choice_num <= len(patterns):
                name, func = patterns[choice_num - 1]
                
                # Get parameters
                size = input("Enter size (1-50, default=5): ").strip()
                size = int(size) if size else 5

                if not PatternUtils.validate_size(size)[0]:
                    print("Invalid size! Using default size 5.")
                    size = 5

                # Check if pattern uses start_num
                patterns_without_start = ["Pascal's Triangle", "Prime Numbers", "Fibonacci Triangle", "Multiplication Table", "Magic Square", "Sierpinski Triangle", "Mandelbrot Set", "Hilbert Curve", "Dragon Curve", "Koch Snowflake", "Cellular Automaton", "Binary Tree"]
                if name in patterns_without_start:
                    start_num = 1  # Not used but set for consistency
                    print_separator(f"Generating {name}")
                    demo_pattern(name, func, size, start_num)
                else:
                    start_num = input("Enter start number (0-1000, default=1): ").strip()
                    start_num = int(start_num) if start_num else 1

                    if not PatternUtils.validate_start_number(start_num)[0]:
                        print("Invalid start number! Using default start number 1.")
                        start_num = 1

                    print_separator(f"Generating {name}")
                    demo_pattern(name, func, size, start_num)
                
                input("\nPress Enter to continue...")
            else:
                print("Invalid choice! Please try again.")
                
        except ValueError:
            print("Invalid input! Please enter a number.")
        except KeyboardInterrupt:
            print("\n\nExiting demo...")
            break


def batch_demo():
    """Batch demo showing all patterns with default parameters"""
    algorithms = PatternAlgorithms()
    
    print_separator("Python Number Pattern Generator - Batch Demo")
    print("Developed by Molla Samser (RSK World)")
    print("Designed by Rima Khatun")
    print("Website: https://rskworld.in")
    print("© 2026 RSK World. All rights reserved.")
    
    demo_patterns = [
        ("Pyramid", algorithms.pyramid, 5, 1),
        ("Reverse Pyramid", algorithms.reverse_pyramid, 5, 1),
        ("Triangle", algorithms.triangle, 5, 1),
        ("Pascal's Triangle", algorithms.pascal_triangle, 5, 1),
        ("Floyd's Triangle", algorithms.floyd_triangle, 4, 1),
        ("Square", algorithms.square, 3, 1),
        ("Diamond", algorithms.diamond, 3, 1),
        ("Hourglass", algorithms.hourglass, 4, 1),
        ("Spiral", algorithms.spiral, 3, 1),
        ("Prime Numbers", algorithms.prime_numbers, 3, 1),
        ("Fibonacci Triangle", algorithms.fibonacci_triangle, 5, 1),
        ("Multiplication Table", algorithms.multiplication_table, 5, 1),
        ("Magic Square", algorithms.magic_square, 3, 1),
        ("Sierpinski Triangle", algorithms.sierpinski_triangle, 3, 1),
        ("Mandelbrot Set", algorithms.mandelbrot_set, 8, 1),
        ("Hilbert Curve", algorithms.hilbert_curve, 2, 1),
        ("Dragon Curve", algorithms.dragon_curve, 4, 1),
        ("Koch Snowflake", algorithms.koch_snowflake, 2, 1),
        ("Cellular Automaton", algorithms.cellular_automaton, 8, 1),
        ("Binary Tree", algorithms.binary_tree, 3, 1),
    ]
    
    for name, func, size, start_num in demo_patterns:
        demo_pattern(name, func, size, start_num)
        input("\nPress Enter to continue to next pattern...")


def performance_test():
    """Performance test for pattern generation"""
    algorithms = PatternAlgorithms()
    
    print_separator("Performance Test")
    print("Testing pattern generation performance with different sizes...")
    
    test_sizes = [5, 10, 15, 20]
    test_patterns = [
        ("Pyramid", algorithms.pyramid),
        ("Spiral", algorithms.spiral),
        ("Prime Numbers", algorithms.prime_numbers),
        ("Magic Square", algorithms.magic_square),
        ("Multiplication Table", algorithms.multiplication_table),
        ("Sierpinski Triangle", algorithms.sierpinski_triangle),
        ("Mandelbrot Set", algorithms.mandelbrot_set),
        ("Hilbert Curve", algorithms.hilbert_curve),
    ]
    
    print(f"{'Pattern':<20} {'Size':<6} {'Time (ms)':<10} {'Lines':<8}")
    print("-" * 50)
    
    for name, func in test_patterns:
        for size in test_sizes:
            start_time = time.time()

            if name in ["Prime Numbers", "Magic Square", "Multiplication Table", "Sierpinski Triangle", "Mandelbrot Set", "Hilbert Curve", "Dragon Curve", "Koch Snowflake", "Cellular Automaton", "Binary Tree"]:
                pattern = func(size)
            else:
                pattern = func(size, 1)
            
            end_time = time.time()
            generation_time = (end_time - start_time) * 1000
            lines = PatternUtils.count_pattern_lines(pattern)
            
            print(f"{name:<20} {size:<6} {generation_time:<10.2f} {lines:<8}")


def main():
    """Main function for demo script"""
    print("Python Number Pattern Generator - Demo Script")
    print("=" * 60)
    
    while True:
        print("\nDemo Options:")
        print("1. Interactive Demo (Choose patterns interactively)")
        print("2. Batch Demo (Show all patterns)")
        print("3. Performance Test")
        print("4. Exit")
        
        choice = input("\nEnter your choice (1-4): ").strip()
        
        if choice == "1":
            interactive_demo()
        elif choice == "2":
            batch_demo()
        elif choice == "3":
            performance_test()
        elif choice == "4":
            print("\nThank you for using Python Number Pattern Generator Demo!")
            print("Visit https://rskworld.in for more projects and resources.")
            break
        else:
            print("Invalid choice! Please try again.")


if __name__ == "__main__":
    main()
240 lines•9.3 KB
python

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.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer