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
web_app.pyindex.html
web_app.py
Raw Download
Find: Go to:
"""
Flask Web Application for Python Number Pattern Generator
Author: Molla Samser (Founder, RSK World)
Designer & Tester: Rima Khatun
Website: https://rskworld.in
Year: 2026
Description: Full web interface for pattern generation
"""

from flask import Flask, render_template, request, jsonify, send_file, make_response
from patterns import PatternAlgorithms, PatternUtils
import json
import io
from datetime import datetime

app = Flask(__name__)
app.config['SECRET_KEY'] = 'rsk-world-pattern-generator-2026'

# Initialize pattern algorithms
algorithms = PatternAlgorithms()

# Available patterns
PATTERN_TYPES = {
    'pyramid': 'Pyramid Pattern',
    'reverse_pyramid': 'Reverse Pyramid',
    'triangle': 'Number Triangle',
    'pascal': 'Pascal\'s Triangle',
    'floyd': 'Floyd\'s Triangle',
    'square': 'Number Square',
    'diamond': 'Diamond Pattern',
    'hourglass': 'Hourglass Pattern',
    'spiral': 'Number Spiral',
    'prime': 'Prime Numbers',
    'fibonacci': 'Fibonacci Triangle',
    'multiplication': 'Multiplication Table',
    'magic': 'Magic Square',
    'sierpinski': 'Sierpinski Triangle',
    'mandelbrot': 'Mandelbrot Set',
    'hilbert': 'Hilbert Curve',
    'dragon': 'Dragon Curve',
    'koch': 'Koch Snowflake',
    'cellular': 'Cellular Automaton',
    'binary_tree': 'Binary Tree'
}

# Patterns that don't use start_num
PATTERNS_WITHOUT_START_NUM = [
    'pascal', 'prime', 'fibonacci', 'multiplication', 'magic',
    'sierpinski', 'mandelbrot', 'hilbert', 'dragon', 'koch', 'cellular', 'binary_tree'
]

@app.route('/')
def index():
    """Main page"""
    return render_template('index.html',
                         patterns=PATTERN_TYPES,
                         current_year=datetime.now().year)

@app.route('/generate', methods=['POST'])
def generate_pattern():
    """Generate pattern via AJAX"""
    try:
        data = request.get_json()
        pattern_type = data.get('pattern_type', 'pyramid')
        size = int(data.get('size', 5))
        start_num = int(data.get('start_num', 1))

        # Validate inputs
        if not PatternUtils.validate_size(size)[0]:
            return jsonify({'error': 'Invalid size. Must be between 1 and 50.'})

        if pattern_type not in PATTERNS_WITHOUT_START_NUM:
            if not PatternUtils.validate_start_number(start_num)[0]:
                return jsonify({'error': 'Invalid start number. Must be between 0 and 1000.'})

        # Generate pattern
        if pattern_type == 'pyramid':
            pattern = algorithms.pyramid(size, start_num)
        elif pattern_type == 'reverse_pyramid':
            pattern = algorithms.reverse_pyramid(size, start_num)
        elif pattern_type == 'triangle':
            pattern = algorithms.triangle(size, start_num)
        elif pattern_type == 'pascal':
            pattern = algorithms.pascal_triangle(size)
        elif pattern_type == 'floyd':
            pattern = algorithms.floyd_triangle(size)
        elif pattern_type == 'square':
            pattern = algorithms.square(size, start_num)
        elif pattern_type == 'diamond':
            pattern = algorithms.diamond(size, start_num)
        elif pattern_type == 'hourglass':
            pattern = algorithms.hourglass(size, start_num)
        elif pattern_type == 'spiral':
            pattern = algorithms.spiral(size)
        elif pattern_type == 'prime':
            pattern = algorithms.prime_numbers(size)
        elif pattern_type == 'fibonacci':
            pattern = algorithms.fibonacci_triangle(size)
        elif pattern_type == 'multiplication':
            pattern = algorithms.multiplication_table(size)
        elif pattern_type == 'magic':
            pattern = algorithms.magic_square(size)
        elif pattern_type == 'sierpinski':
            pattern = algorithms.sierpinski_triangle(min(size, 5))
        elif pattern_type == 'mandelbrot':
            pattern = algorithms.mandelbrot_set(min(size, 15))
        elif pattern_type == 'hilbert':
            pattern = algorithms.hilbert_curve(min(size, 4))
        elif pattern_type == 'dragon':
            pattern = algorithms.dragon_curve(min(size, 8))
        elif pattern_type == 'koch':
            pattern = algorithms.koch_snowflake(min(size, 3))
        elif pattern_type == 'cellular':
            pattern = algorithms.cellular_automaton(size, start_num if start_num <= 255 else 30)
        elif pattern_type == 'binary_tree':
            pattern = algorithms.binary_tree(min(size, 5))
        else:
            return jsonify({'error': 'Pattern type not implemented.'})

        # Get pattern statistics
        stats = PatternUtils.get_pattern_stats(pattern)

        return jsonify({
            'pattern': pattern,
            'stats': stats,
            'pattern_type': PATTERN_TYPES.get(pattern_type, pattern_type),
            'size': size,
            'start_num': start_num
        })

    except Exception as e:
        return jsonify({'error': f'Error generating pattern: {str(e)}'})

@app.route('/api/patterns', methods=['GET'])
def get_patterns():
    """Get list of available patterns"""
    return jsonify({
        'patterns': PATTERN_TYPES,
        'patterns_without_start_num': PATTERNS_WITHOUT_START_NUM
    })

@app.route('/api/generate/<pattern_type>', methods=['GET'])
def api_generate_pattern(pattern_type):
    """REST API for pattern generation"""
    try:
        size = int(request.args.get('size', 5))
        start_num = int(request.args.get('start_num', 1))

        # Validate inputs
        if not PatternUtils.validate_size(size)[0]:
            return jsonify({'error': 'Invalid size'}), 400

        if pattern_type not in PATTERNS_WITHOUT_START_NUM:
            if not PatternUtils.validate_start_number(start_num)[0]:
                return jsonify({'error': 'Invalid start number'}), 400

        # Generate pattern
        if pattern_type == 'pyramid':
            pattern = algorithms.pyramid(size, start_num)
        elif pattern_type == 'reverse_pyramid':
            pattern = algorithms.reverse_pyramid(size, start_num)
        elif pattern_type == 'triangle':
            pattern = algorithms.triangle(size, start_num)
        elif pattern_type == 'pascal':
            pattern = algorithms.pascal_triangle(size)
        elif pattern_type == 'floyd':
            pattern = algorithms.floyd_triangle(size)
        elif pattern_type == 'square':
            pattern = algorithms.square(size, start_num)
        elif pattern_type == 'diamond':
            pattern = algorithms.diamond(size, start_num)
        elif pattern_type == 'hourglass':
            pattern = algorithms.hourglass(size, start_num)
        elif pattern_type == 'spiral':
            pattern = algorithms.spiral(size)
        elif pattern_type == 'prime':
            pattern = algorithms.prime_numbers(size)
        elif pattern_type == 'fibonacci':
            pattern = algorithms.fibonacci_triangle(size)
        elif pattern_type == 'multiplication':
            pattern = algorithms.multiplication_table(size)
        elif pattern_type == 'magic':
            pattern = algorithms.magic_square(size)
        elif pattern_type == 'sierpinski':
            pattern = algorithms.sierpinski_triangle(min(size, 5))
        elif pattern_type == 'mandelbrot':
            pattern = algorithms.mandelbrot_set(min(size, 15))
        elif pattern_type == 'hilbert':
            pattern = algorithms.hilbert_curve(min(size, 4))
        elif pattern_type == 'dragon':
            pattern = algorithms.dragon_curve(min(size, 8))
        elif pattern_type == 'koch':
            pattern = algorithms.koch_snowflake(min(size, 3))
        elif pattern_type == 'cellular':
            pattern = algorithms.cellular_automaton(size, start_num if start_num <= 255 else 30)
        elif pattern_type == 'binary_tree':
            pattern = algorithms.binary_tree(min(size, 5))
        else:
            return jsonify({'error': 'Pattern not found'}), 404

        return jsonify({
            'pattern': pattern,
            'pattern_type': PATTERN_TYPES.get(pattern_type, pattern_type),
            'size': size,
            'start_num': start_num if pattern_type not in PATTERNS_WITHOUT_START_NUM else None
        })

    except Exception as e:
        return jsonify({'error': str(e)}), 500

@app.route('/export/<pattern_type>', methods=['POST'])
def export_pattern(pattern_type):
    """Export pattern as file"""
    try:
        data = request.get_json()
        size = int(data.get('size', 5))
        start_num = int(data.get('start_num', 1))
        format_type = data.get('format', 'txt')

        # Generate pattern
        if pattern_type == 'pyramid':
            pattern = algorithms.pyramid(size, start_num)
        elif pattern_type == 'reverse_pyramid':
            pattern = algorithms.reverse_pyramid(size, start_num)
        elif pattern_type == 'triangle':
            pattern = algorithms.triangle(size, start_num)
        elif pattern_type == 'pascal':
            pattern = algorithms.pascal_triangle(size)
        elif pattern_type == 'floyd':
            pattern = algorithms.floyd_triangle(size)
        elif pattern_type == 'square':
            pattern = algorithms.square(size, start_num)
        elif pattern_type == 'diamond':
            pattern = algorithms.diamond(size, start_num)
        elif pattern_type == 'hourglass':
            pattern = algorithms.hourglass(size, start_num)
        elif pattern_type == 'spiral':
            pattern = algorithms.spiral(size)
        elif pattern_type == 'prime':
            pattern = algorithms.prime_numbers(size)
        elif pattern_type == 'fibonacci':
            pattern = algorithms.fibonacci_triangle(size)
        elif pattern_type == 'multiplication':
            pattern = algorithms.multiplication_table(size)
        elif pattern_type == 'magic':
            pattern = algorithms.magic_square(size)
        elif pattern_type == 'sierpinski':
            pattern = algorithms.sierpinski_triangle(min(size, 5))
        elif pattern_type == 'mandelbrot':
            pattern = algorithms.mandelbrot_set(min(size, 15))
        elif pattern_type == 'hilbert':
            pattern = algorithms.hilbert_curve(min(size, 4))
        elif pattern_type == 'dragon':
            pattern = algorithms.dragon_curve(min(size, 8))
        elif pattern_type == 'koch':
            pattern = algorithms.koch_snowflake(min(size, 3))
        elif pattern_type == 'cellular':
            pattern = algorithms.cellular_automaton(size, start_num if start_num <= 255 else 30)
        elif pattern_type == 'binary_tree':
            pattern = algorithms.binary_tree(min(size, 5))
        else:
            return jsonify({'error': 'Pattern not found'}), 404

        # Create file content
        filename = f"pattern_{pattern_type}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
        content = f"Python Number Pattern Generator\n"
        content += "=" * 40 + "\n"
        content += f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
        content += f"Pattern Type: {PATTERN_TYPES.get(pattern_type, pattern_type)}\n"
        content += f"Size: {size}\n"
        if pattern_type not in PATTERNS_WITHOUT_START_NUM:
            content += f"Start Number: {start_num}\n"
        content += "\n" + "=" * 40 + "\n"
        content += "Pattern Output:\n"
        content += "-" * 20 + "\n\n"
        content += pattern
        content += "\n\n" + "=" * 40 + "\n"
        content += "Generated by Python Number Pattern Generator\n"
        content += "Developed by Molla Samser (RSK World)\n"
        content += "Designed by Rima Khatun\n"
        content += "Website: https://rskworld.in\n"
        content += "© 2026 RSK World. All rights reserved.\n"

        if format_type == 'txt':
            response = make_response(content)
            response.headers['Content-Type'] = 'text/plain'
            response.headers['Content-Disposition'] = f'attachment; filename={filename}.txt'
        else:
            # JSON format
            response = make_response(json.dumps({
                'pattern': pattern,
                'metadata': {
                    'pattern_type': PATTERN_TYPES.get(pattern_type, pattern_type),
                    'size': size,
                    'start_num': start_num if pattern_type not in PATTERNS_WITHOUT_START_NUM else None,
                    'generated_at': datetime.now().isoformat(),
                    'generator': 'Python Number Pattern Generator',
                    'author': 'Molla Samser (RSK World)',
                    'designer': 'Rima Khatun'
                }
            }, indent=2))
            response.headers['Content-Type'] = 'application/json'
            response.headers['Content-Disposition'] = f'attachment; filename={filename}.json'

        return response

    except Exception as e:
        return jsonify({'error': str(e)}), 500

@app.route('/health')
def health_check():
    """Health check endpoint"""
    return jsonify({
        'status': 'healthy',
        'version': '2.0',
        'patterns_available': len(PATTERN_TYPES),
        'timestamp': datetime.now().isoformat()
    })

if __name__ == '__main__':
    print("Starting Python Number Pattern Generator Web App...")
    print("Developed by Molla Samser (RSK World)")
    print("Designed by Rima Khatun")
    print("Website: https://rskworld.in")
    print("© 2026 RSK World. All rights reserved.")
    print("\nVisit http://localhost:5000 to access the web interface")
    print("API endpoints available at http://localhost:5000/api/")
    app.run(debug=True, host='0.0.0.0', port=5000)
328 lines•13.6 KB
python
index.html
Raw Download
Find: Go to:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Python Number Pattern Generator - RSK World</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            color: #333;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        header {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 30px;
            text-align: center;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        h1 {
            color: #2c3e50;
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .subtitle {
            color: #7f8c8d;
            font-size: 1.2em;
            margin-bottom: 20px;
        }
        
        .author-info {
            background: #ecf0f1;
            padding: 15px;
            border-radius: 10px;
            margin-top: 20px;
        }
        
        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .feature-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
        }
        
        .feature-icon {
            font-size: 2.5em;
            margin-bottom: 15px;
        }
        
        .feature-title {
            color: #2c3e50;
            font-size: 1.3em;
            margin-bottom: 10px;
        }
        
        .demo-section {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        }
        
        .pattern-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        
        .pattern-card {
            background: #f8f9fa;
            border: 2px solid #e9ecef;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
        }
        
        .pattern-preview {
            font-family: 'Courier New', monospace;
            background: #2c3e50;
            color: #ecf0f1;
            padding: 15px;
            border-radius: 8px;
            margin-top: 10px;
            font-size: 0.9em;
            line-height: 1.4;
            overflow-x: auto;
        }
        
        .download-section {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 30px;
            text-align: center;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        }
        
        .btn {
            display: inline-block;
            background: #3498db;
            color: white;
            padding: 12px 30px;
            text-decoration: none;
            border-radius: 25px;
            margin: 10px;
            transition: background 0.3s ease;
            font-weight: bold;
        }
        
        .btn:hover {
            background: #2980b9;
        }
        
        .btn-success {
            background: #27ae60;
        }
        
        .btn-success:hover {
            background: #229954;
        }
        
        .footer {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 20px;
            text-align: center;
            margin-top: 30px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        }
        
        @media (max-width: 768px) {
            h1 {
                font-size: 2em;
            }
            
            .features {
                grid-template-columns: 1fr;
            }
            
            .pattern-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>🔢 Python Number Pattern Generator</h1>
            <p class="subtitle">Comprehensive number pattern generator with GUI interface</p>
            
            <div class="author-info">
                <strong>Developed by:</strong> Molla Samser (Founder, RSK World)<br>
                <strong>Designed & Tested by:</strong> Rima Khatun<br>
                <strong>Website:</strong> <a href="https://rskworld.in" target="_blank">https://rskworld.in</a><br>
                <strong>Email:</strong> hello@rskworld.in, support@rskworld.in<br>
                <strong>Phone:</strong> +91 93305 39277<br>
                <strong>Address:</strong> Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India - 713147<br>
                <strong>Year:</strong> 2026
            </div>
        </header>

        <section class="features">
            <div class="feature-card">
                <div class="feature-icon">🎯</div>
                <h3 class="feature-title">Multiple Pattern Types</h3>
                <p>Choose from 10 different pattern types including pyramid, diamond, spiral, and mathematical patterns like Pascal's triangle.</p>
            </div>
            
            <div class="feature-card">
                <div class="feature-icon">⚙️</div>
                <h3 class="feature-title">Customizable Parameters</h3>
                <p>Adjust size, starting numbers, and other parameters to create unique patterns tailored to your needs.</p>
            </div>
            
            <div class="feature-card">
                <div class="feature-icon">🖥️</div>
                <h3 class="feature-title">GUI Interface</h3>
                <p>User-friendly interface built with Tkinter provides an intuitive experience for pattern generation.</p>
            </div>
            
            <div class="feature-card">
                <div class="feature-icon">💾</div>
                <h3 class="feature-title">Pattern Export</h3>
                <p>Save your generated patterns to text files with detailed information and timestamps.</p>
            </div>
            
            <div class="feature-card">
                <div class="feature-icon">📚</div>
                <h3 class="feature-title">Educational Value</h3>
                <p>Perfect for learning Python loops, conditional statements, and algorithmic thinking.</p>
            </div>
            
            <div class="feature-card">
                <div class="feature-icon">🚀</div>
                <h3 class="feature-title">Easy to Use</h3>
                <p>Simple installation and intuitive interface make it accessible for beginners and experts alike.</p>
            </div>
        </section>

        <section class="demo-section">
            <h2>Pattern Examples</h2>
            <p>Here are some examples of patterns you can generate:</p>
            
            <div class="pattern-grid">
                <div class="pattern-card">
                    <h4>Pyramid Pattern</h4>
                    <div class="pattern-preview">
        1
      1 2
    1 2 3
  1 2 3 4
1 2 3 4 5
                    </div>
                </div>
                
                <div class="pattern-card">
                    <h4>Diamond Pattern</h4>
                    <div class="pattern-preview">
    1
   121
  12321
   121
    1
                    </div>
                </div>
                
                <div class="pattern-card">
                    <h4>Number Spiral</h4>
                    <div class="pattern-preview">
  1  2  3
  8  9  4
  7  6  5
                    </div>
                </div>
                
                <div class="pattern-card">
                    <h4>Pascal's Triangle</h4>
                    <div class="pattern-preview">
    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1
                    </div>
                </div>
            </div>
        </section>

        <section class="download-section">
            <h2>Download & Installation</h2>
            <p>Get started with the Python Number Pattern Generator today!</p>
            
            <a href="../python-pattern-generator.zip" class="btn">📦 Download Project</a>
            <a href="https://github.com/rskworld/python-pattern-generator" class="btn btn-success" target="_blank">🐙 View on GitHub</a>
            
            <h3 style="margin-top: 30px;">Quick Start</h3>
            <div style="text-align: left; max-width: 600px; margin: 20px auto;">
                <ol>
                    <li>Download and extract the project files</li>
                    <li>Ensure you have Python 3.6+ installed</li>
                    <li>Run the GUI application: <code>python main.py</code></li>
                    <li>Or try the demo: <code>python demo.py</code></li>
                </ol>
            </div>
        </section>

        <footer class="footer">
            <p><strong>© 2026 RSK World. All rights reserved.</strong></p>
            <p>Developed with ❤️ for educational purposes</p>
            <p>
                <a href="https://rskworld.in" target="_blank">Website</a> | 
                <a href="mailto:hello@rskworld.in">Contact</a> | 
                <a href="https://rskworld.in/terms.php" target="_blank">Terms</a> | 
                <a href="https://rskworld.in/privacy.php" target="_blank">Privacy</a>
            </p>
        </footer>
    </div>
</body>
</html>
312 lines•10.1 KB
markup

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