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
star-pattern-maker
/
js
RSK World
star-pattern-maker
Star Pattern Maker - HTML5 Canvas + 3D Rendering + Physics Simulation + AI Patterns + Generative Audio + Modern UI + Glassmorphism Design
js
  • 3d-engine.js3.8 KB
  • ai-patterns.js5.6 KB
  • animations.js1.4 KB
  • audio.js1.3 KB
  • controls.js12.2 KB
  • export.js3.9 KB
  • filters.js3.5 KB
  • fractals.js3.5 KB
  • gallery.js2.5 KB
  • main.js1.9 KB
  • particles.js1.4 KB
  • physics.js1.7 KB
  • presets.js2.8 KB
  • randomizer.js1.4 KB
  • renderer.js7 KB
  • shaders.js6.5 KB
  • shapes.js1.7 KB
  • sound-gen.js4.4 KB
  • state.js1.9 KB
  • symmetry.js3.9 KB
  • themes.js1.4 KB
  • timeline.js4.2 KB
  • utils.js546 B
gallery.js
js/gallery.js
Raw Download
Find: Go to:
/* V7 Gallery Module */
import { state } from './state.js';

const STORAGE_KEY = 'star_patterns_gallery';

export function savePattern(name, thumbDataUrl) {
    const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
    const pattern = {
        id: Date.now(),
        name: name || 'Untitled Pattern',
        date: new Date().toLocaleDateString(),
        thumbnail: thumbDataUrl,
        state: { ...state } // Clone state
    };
    saved.unshift(pattern); // Add to top
    localStorage.setItem(STORAGE_KEY, JSON.stringify(saved));
    renderGallery();
}

export function loadPattern(id) {
    const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
    const pattern = saved.find(p => p.id === id);
    if (pattern) {
        // Restore State
        Object.keys(pattern.state).forEach(k => {
            state[k] = pattern.state[k];
        });
        return true;
    }
    return false;
}

export function deletePattern(id) {
    let saved = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
    saved = saved.filter(p => p.id !== id);
    localStorage.setItem(STORAGE_KEY, JSON.stringify(saved));
    renderGallery();
}

export function renderGallery() {
    const container = document.getElementById('galleryContainer');
    if (!container) return; // Should exist in HTML

    const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');

    if (saved.length === 0) {
        container.innerHTML = '<p style="color:var(--text-secondary); text-align:center;">No saved patterns</p>';
        return;
    }

    container.innerHTML = '';
    saved.forEach(p => {
        const item = document.createElement('div');
        item.className = 'gallery-item';
        item.innerHTML = `
            <img src="${p.thumbnail}" alt="${p.name}">
            <div class="info">
                <span>${p.name}</span>
                <button class="btn-sm delete-btn" data-id="${p.id}">&times;</button>
            </div>
        `;

        // Load click
        item.querySelector('img').addEventListener('click', () => {
            const event = new CustomEvent('loadPattern', { detail: p.id });
            window.dispatchEvent(event);
        });

        // Delete click
        item.querySelector('.delete-btn').addEventListener('click', (e) => {
            e.stopPropagation();
            if (confirm('Delete this pattern?')) deletePattern(p.id);
        });

        container.appendChild(item);
    });
}
78 lines•2.5 KB
javascript

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