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
RELEASE_NOTES.mdai-patterns.js
js/ai-patterns.js
Raw Download
Find: Go to:
/* V14 AI Patterns Module - Procedural Pattern Generation */
import { state } from './state.js';
import { drawStarPath } from './shapes.js';

/**
 * Generate Neural Network inspired pattern
 */
export function drawNeuralPattern(ctx, w, h, rOuter, rInner) {
    const cx = w / 2;
    const cy = h / 2;
    const nodes = 20;
    const nodePositions = [];

    // Generate random node positions
    for (let i = 0; i < nodes; i++) {
        const angle = (Math.PI * 2 * i) / nodes;
        const radius = Math.random() * Math.min(w, h) / 3 + 50;
        nodePositions.push({
            x: cx + Math.cos(angle) * radius,
            y: cy + Math.sin(angle) * radius
        });
    }

    // Draw connections
    ctx.save();
    ctx.strokeStyle = state.strokeColor;
    ctx.lineWidth = 1;
    ctx.globalAlpha = 0.3;

    for (let i = 0; i < nodes; i++) {
        for (let j = i + 1; j < nodes; j++) {
            const dist = Math.hypot(
                nodePositions[i].x - nodePositions[j].x,
                nodePositions[i].y - nodePositions[j].y
            );

            if (dist < 200) {
                ctx.beginPath();
                ctx.moveTo(nodePositions[i].x, nodePositions[i].y);
                ctx.lineTo(nodePositions[j].x, nodePositions[j].y);
                ctx.stroke();
            }
        }
    }

    ctx.restore();

    // Draw nodes as small stars
    ctx.globalAlpha = 1;
    nodePositions.forEach(pos => {
        ctx.save();
        ctx.translate(pos.x, pos.y);
        ctx.beginPath();
        drawStarPath(ctx, state.spikes, rOuter / 4, rInner / 4, state.curve, state.twist);
        ctx.fill();
        if (state.lineWidth > 0) ctx.stroke();
        ctx.restore();
    });
}

/**
 * Generate L-System fractal pattern
 */
export function drawLSystem(ctx, w, h, rOuter, rInner) {
    const cx = w / 2;
    const cy = h / 2;

    // Simple L-System: Koch curve variant
    const axiom = 'F';
    const rules = { 'F': 'F+F-F-F+F' };
    const iterations = 3;
    const angle = 90;
    const length = 10;

    let current = axiom;

    // Generate string
    for (let i = 0; i < iterations; i++) {
        let next = '';
        for (let char of current) {
            next += rules[char] || char;
        }
        current = next;
    }

    // Draw
    ctx.save();
    ctx.translate(cx - 100, cy);
    ctx.strokeStyle = state.strokeColor;
    ctx.lineWidth = 2;

    let currentAngle = 0;
    let x = 0, y = 0;

    ctx.beginPath();
    ctx.moveTo(x, y);

    for (let char of current) {
        if (char === 'F') {
            x += Math.cos(currentAngle * Math.PI / 180) * length;
            y += Math.sin(currentAngle * Math.PI / 180) * length;
            ctx.lineTo(x, y);
        } else if (char === '+') {
            currentAngle += angle;
        } else if (char === '-') {
            currentAngle -= angle;
        }
    }

    ctx.stroke();
    ctx.restore();
}

/**
 * Generate Voronoi diagram pattern
 */
export function drawVoronoi(ctx, w, h, rOuter, rInner) {
    const points = 15;
    const seeds = [];

    // Generate random seed points
    for (let i = 0; i < points; i++) {
        seeds.push({
            x: Math.random() * w,
            y: Math.random() * h,
            color: `hsl(${Math.random() * 360}, 70%, 50%)`
        });
    }

    // Draw Voronoi cells
    const imageData = ctx.createImageData(w, h);
    const data = imageData.data;

    for (let y = 0; y < h; y += 2) {
        for (let x = 0; x < w; x += 2) {
            let minDist = Infinity;
            let closestSeed = null;

            // Find closest seed
            for (let seed of seeds) {
                const dist = Math.hypot(x - seed.x, y - seed.y);
                if (dist < minDist) {
                    minDist = dist;
                    closestSeed = seed;
                }
            }

            // Color pixel based on closest seed
            if (closestSeed) {
                const idx = (y * w + x) * 4;
                const rgb = hslToRgb(closestSeed.color);
                data[idx] = rgb.r;
                data[idx + 1] = rgb.g;
                data[idx + 2] = rgb.b;
                data[idx + 3] = 255;
            }
        }
    }

    ctx.putImageData(imageData, 0, 0);

    // Draw stars at seed points
    seeds.forEach(seed => {
        ctx.save();
        ctx.translate(seed.x, seed.y);
        ctx.fillStyle = seed.color;
        ctx.beginPath();
        drawStarPath(ctx, state.spikes, rOuter / 3, rInner / 3, state.curve, state.twist);
        ctx.fill();
        ctx.restore();
    });
}

/**
 * Helper: Convert HSL to RGB
 */
function hslToRgb(hslString) {
    const match = hslString.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/);
    if (!match) return { r: 255, g: 255, b: 255 };

    const h = parseInt(match[1]) / 360;
    const s = parseInt(match[2]) / 100;
    const l = parseInt(match[3]) / 100;

    let r, g, b;

    if (s === 0) {
        r = g = b = l;
    } else {
        const hue2rgb = (p, q, t) => {
            if (t < 0) t += 1;
            if (t > 1) t -= 1;
            if (t < 1 / 6) return p + (q - p) * 6 * t;
            if (t < 1 / 2) return q;
            if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
            return p;
        };

        const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
        const p = 2 * l - q;
        r = hue2rgb(p, q, h + 1 / 3);
        g = hue2rgb(p, q, h);
        b = hue2rgb(p, q, h - 1 / 3);
    }

    return {
        r: Math.round(r * 255),
        g: Math.round(g * 255),
        b: Math.round(b * 255)
    };
}
212 lines•5.6 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