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
  • Blog
  • 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
app.jsfilters.jssymmetry.jssound-gen.js
js/filters.js
Raw Download
Find: Go to:
/* V13 Filters Module - Post-Processing Effects */
import { state } from './state.js';

/**
 * Apply all enabled filters to the canvas
 */
export function applyFilters(ctx, canvas) {
    if (state.glitchEnabled) {
        applyGlitch(ctx, canvas);
    }

    if (state.scanlinesEnabled) {
        applyScanlines(ctx, canvas);
    }

    if (state.vignetteEnabled) {
        applyVignette(ctx, canvas);
    }

    if (state.bloomEnabled) {
        applyBloom(ctx, canvas);
    }

    if (state.pixelateEnabled) {
        applyPixelate(ctx, canvas);
    }

    if (state.invertEnabled) {
        applyInvert(ctx, canvas);
    }
}

/**
 * Glitch Effect - RGB channel separation
 */
function applyGlitch(ctx, canvas) {
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;

    // Random offset
    const offset = Math.floor(Math.random() * 10) - 5;

    // Shift red channel
    for (let i = 0; i < data.length; i += 4) {
        if (i + offset * 4 >= 0 && i + offset * 4 < data.length) {
            data[i] = data[i + offset * 4]; // R
        }
    }

    ctx.putImageData(imageData, 0, 0);
}

/**
 * Scanlines - CRT monitor effect
 */
function applyScanlines(ctx, canvas) {
    ctx.globalAlpha = 0.1;
    ctx.fillStyle = '#000000';

    for (let y = 0; y < canvas.height; y += 4) {
        ctx.fillRect(0, y, canvas.width, 2);
    }

    ctx.globalAlpha = 1.0;
}

/**
 * Vignette - Darkened edges
 */
function applyVignette(ctx, canvas) {
    const cx = canvas.width / 2;
    const cy = canvas.height / 2;
    const radius = Math.max(canvas.width, canvas.height) / 2;

    const gradient = ctx.createRadialGradient(cx, cy, radius * 0.3, cx, cy, radius);
    gradient.addColorStop(0, 'rgba(0,0,0,0)');
    gradient.addColorStop(1, 'rgba(0,0,0,0.7)');

    ctx.fillStyle = gradient;
    ctx.fillRect(0, 0, canvas.width, canvas.height);
}

/**
 * Bloom - Glow overflow effect
 * Note: This is a simplified version. True bloom requires multiple passes.
 */
function applyBloom(ctx, canvas) {
    ctx.save();
    ctx.globalCompositeOperation = 'screen';
    ctx.globalAlpha = 0.3;
    ctx.filter = 'blur(20px)';
    ctx.drawImage(canvas, 0, 0);
    ctx.filter = 'none';
    ctx.restore();
}

/**
 * Pixelate - Retro pixel art look
 */
function applyPixelate(ctx, canvas) {
    const pixelSize = 8;
    const w = canvas.width;
    const h = canvas.height;

    // Get current canvas
    const imageData = ctx.getImageData(0, 0, w, h);

    // Downsample
    ctx.imageSmoothingEnabled = false;
    const tempCanvas = document.createElement('canvas');
    tempCanvas.width = Math.floor(w / pixelSize);
    tempCanvas.height = Math.floor(h / pixelSize);
    const tempCtx = tempCanvas.getContext('2d');
    tempCtx.drawImage(canvas, 0, 0, tempCanvas.width, tempCanvas.height);

    // Upsample
    ctx.clearRect(0, 0, w, h);
    ctx.drawImage(tempCanvas, 0, 0, w, h);
    ctx.imageSmoothingEnabled = true;
}

/**
 * Invert Colors - Negative image
 */
function applyInvert(ctx, canvas) {
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;

    for (let i = 0; i < data.length; i += 4) {
        data[i] = 255 - data[i];         // R
        data[i + 1] = 255 - data[i + 1]; // G
        data[i + 2] = 255 - data[i + 2]; // B
        // Alpha unchanged
    }

    ctx.putImageData(imageData, 0, 0);
}
138 lines•3.5 KB
javascript
js/symmetry.js
Raw Download
Find: Go to:
/* V13 Symmetry Module - Advanced Symmetry Patterns */
import { state } from './state.js';
import { drawStarPath } from './shapes.js';
import { renderRecursiveFractal } from './fractals.js';

/**
 * Draw Mandala pattern - Radial + reflective symmetry
 */
export function drawMandala(ctx, w, h, rOuter, rInner, dynamicFill) {
    const cx = w / 2;
    const cy = h / 2;
    const layers = 3; // Number of concentric layers

    ctx.save();
    ctx.translate(cx, cy);

    for (let layer = 0; layer < layers; layer++) {
        const layerRadius = rOuter * (1 - layer * 0.3);
        const layerInner = rInner * (1 - layer * 0.3);
        const segments = 8 + layer * 4; // More segments in outer layers

        for (let i = 0; i < segments; i++) {
            ctx.save();
            ctx.rotate((Math.PI * 2 * i) / segments);

            // Draw star at this position
            ctx.beginPath();
            drawStarPath(ctx, state.spikes, layerRadius / 2, layerInner / 2, state.curve, state.twist);
            ctx.fill();
            if (state.lineWidth > 0) ctx.stroke();

            ctx.restore();
        }
    }

    ctx.restore();
}

/**
 * Draw Spiral pattern - Fibonacci/golden spiral
 */
export function drawSpiral(ctx, w, h, rOuter, rInner, dynamicFill) {
    const cx = w / 2;
    const cy = h / 2;
    const spiralTurns = 3;
    const starsPerTurn = 12;
    const totalStars = spiralTurns * starsPerTurn;

    ctx.save();
    ctx.translate(cx, cy);

    for (let i = 0; i < totalStars; i++) {
        const progress = i / totalStars;
        const angle = progress * spiralTurns * Math.PI * 2;
        const radius = progress * Math.max(w, h) / 2;

        const x = Math.cos(angle) * radius;
        const y = Math.sin(angle) * radius;

        const scale = 1 - progress * 0.7; // Stars get smaller

        ctx.save();
        ctx.translate(x, y);
        ctx.rotate(angle);
        ctx.scale(scale, scale);

        ctx.beginPath();
        drawStarPath(ctx, state.spikes, rOuter / 3, rInner / 3, state.curve, state.twist);
        ctx.fill();
        if (state.lineWidth > 0) ctx.stroke();

        ctx.restore();
    }

    ctx.restore();
}

/**
 * Draw Tessellation - Repeating geometric tiles
 */
export function drawTessellation(ctx, w, h, rOuter, rInner, dynamicFill) {
    const tileSize = rOuter * 2;
    const cols = Math.ceil(w / tileSize) + 1;
    const rows = Math.ceil(h / tileSize) + 1;

    for (let row = 0; row < rows; row++) {
        for (let col = 0; col < cols; col++) {
            const x = col * tileSize - tileSize / 2;
            const y = row * tileSize - tileSize / 2;

            // Offset every other row for hexagonal pattern
            const offsetX = (row % 2) * (tileSize / 2);

            ctx.save();
            ctx.translate(x + offsetX, y);
            ctx.rotate(state.rotation);

            ctx.beginPath();
            drawStarPath(ctx, state.spikes, rOuter / 2, rInner / 2, state.curve, state.twist);
            ctx.fill();
            if (state.lineWidth > 0) ctx.stroke();

            ctx.restore();
        }
    }
}

/**
 * Draw Mirror pattern - Bilateral symmetry
 */
export function drawMirror(ctx, w, h, rOuter, rInner, dynamicFill) {
    const cx = w / 2;
    const cy = h / 2;

    // Draw original
    ctx.save();
    ctx.translate(cx - rOuter, cy);
    ctx.rotate(state.rotation);

    ctx.beginPath();
    drawStarPath(ctx, state.spikes, rOuter, rInner, state.curve, state.twist);
    ctx.fill();
    if (state.lineWidth > 0) ctx.stroke();
    ctx.restore();

    // Draw mirrored
    ctx.save();
    ctx.translate(cx + rOuter, cy);
    ctx.scale(-1, 1); // Flip horizontally
    ctx.rotate(state.rotation);

    ctx.beginPath();
    drawStarPath(ctx, state.spikes, rOuter, rInner, state.curve, state.twist);
    ctx.fill();
    if (state.lineWidth > 0) ctx.stroke();
    ctx.restore();
}
138 lines•3.9 KB
javascript
js/sound-gen.js
Raw Download
Find: Go to:
/* V15 Sound Generation Module - Pattern Sonification */
import { state } from './state.js';

let audioContext = null;
let currentOscillators = [];

/**
 * Initialize audio context
 */
function initAudioContext() {
    if (!audioContext) {
        audioContext = new (window.AudioContext || window.webkitAudioContext)();
    }
    return audioContext;
}

/**
 * Generate tone from frequency
 */
export function generateTone(frequency, duration = 0.5, type = 'sine') {
    const ctx = initAudioContext();
    const oscillator = ctx.createOscillator();
    const gainNode = ctx.createGain();

    oscillator.type = type;
    oscillator.frequency.value = frequency;

    gainNode.gain.setValueAtTime(0.3, ctx.currentTime);
    gainNode.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + duration);

    oscillator.connect(gainNode);
    gainNode.connect(ctx.destination);

    oscillator.start(ctx.currentTime);
    oscillator.stop(ctx.currentTime + duration);

    currentOscillators.push(oscillator);

    // Clean up
    setTimeout(() => {
        const index = currentOscillators.indexOf(oscillator);
        if (index > -1) currentOscillators.splice(index, 1);
    }, duration * 1000);
}

/**
 * Map color to frequency
 */
function colorToFrequency(r, g, b) {
    // Map RGB to musical scale
    const hue = rgbToHue(r, g, b);
    const baseFreq = 220; // A3
    const octaves = 3;

    // Map hue (0-360) to frequency
    const noteIndex = Math.floor((hue / 360) * 12); // 12 notes in octave
    const semitone = Math.pow(2, noteIndex / 12);

    return baseFreq * semitone;
}

/**
 * Convert RGB to Hue
 */
function rgbToHue(r, g, b) {
    r /= 255;
    g /= 255;
    b /= 255;

    const max = Math.max(r, g, b);
    const min = Math.min(r, g, b);
    const delta = max - min;

    let hue = 0;

    if (delta !== 0) {
        if (max === r) {
            hue = ((g - b) / delta) % 6;
        } else if (max === g) {
            hue = (b - r) / delta + 2;
        } else {
            hue = (r - g) / delta + 4;
        }
        hue *= 60;
        if (hue < 0) hue += 360;
    }

    return hue;
}

/**
 * Generate sound from pattern
 */
export function patternToSound(canvas) {
    if (!state.soundEnabled) return;

    const ctx = canvas.getContext('2d');
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;

    // Sample colors from pattern
    const samples = 8;
    const step = Math.floor(data.length / (samples * 4));

    for (let i = 0; i < samples; i++) {
        const idx = i * step * 4;
        const r = data[idx];
        const g = data[idx + 1];
        const b = data[idx + 2];

        const freq = colorToFrequency(r, g, b);
        const delay = i * 0.1;

        setTimeout(() => {
            generateTone(freq, 0.3, 'sine');
        }, delay * 1000);
    }
}

/**
 * Generate melody from geometry
 */
export function geometryToMelody() {
    if (!state.soundEnabled) return;

    const notes = [];
    const baseFreq = 220; // A3

    // Map spikes to notes
    for (let i = 0; i < state.spikes; i++) {
        const semitone = (i % 12);
        const freq = baseFreq * Math.pow(2, semitone / 12);
        notes.push(freq);
    }

    // Play melody
    notes.forEach((freq, i) => {
        setTimeout(() => {
            generateTone(freq, 0.2, 'triangle');
        }, i * 150);
    });
}

/**
 * Stop all sounds
 */
export function stopAllSounds() {
    currentOscillators.forEach(osc => {
        try {
            osc.stop();
        } catch (e) {
            // Already stopped
        }
    });
    currentOscillators = [];
}

/**
 * Create ambient drone from pattern
 */
export function createAmbientDrone() {
    if (!state.soundEnabled) return;

    const ctx = initAudioContext();

    // Create multiple oscillators for richness
    const frequencies = [110, 165, 220]; // A2, E3, A3

    frequencies.forEach((freq, i) => {
        const osc = ctx.createOscillator();
        const gain = ctx.createGain();

        osc.type = 'sine';
        osc.frequency.value = freq;

        gain.gain.setValueAtTime(0, ctx.currentTime);
        gain.gain.linearRampToValueAtTime(0.1, ctx.currentTime + 2);

        osc.connect(gain);
        gain.connect(ctx.destination);

        osc.start(ctx.currentTime);

        currentOscillators.push(osc);
    });
}
187 lines•4.4 KB
javascript
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

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