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
timeline.js
js/timeline.js
Raw Download
Find: Go to:
/* V14 Timeline Module - Keyframe Animation System */
import { state } from './state.js';

class Timeline {
    constructor() {
        this.keyframes = [];
        this.currentTime = 0;
        this.duration = 10000; // 10 seconds
        this.playing = false;
        this.loop = true;
    }

    addKeyframe(time, property, value, easing = 'linear') {
        this.keyframes.push({ time, property, value, easing });
        this.keyframes.sort((a, b) => a.time - b.time);
    }

    play() {
        this.playing = true;
        this.currentTime = 0;
    }

    pause() {
        this.playing = false;
    }

    update(deltaTime) {
        if (!this.playing) return;

        this.currentTime += deltaTime;

        if (this.currentTime >= this.duration) {
            if (this.loop) {
                this.currentTime = 0;
            } else {
                this.pause();
                return;
            }
        }

        // Apply keyframes
        const activeKeyframes = this.keyframes.filter(kf => kf.time <= this.currentTime);

        activeKeyframes.forEach(kf => {
            // Find next keyframe for interpolation
            const nextKf = this.keyframes.find(k =>
                k.property === kf.property && k.time > this.currentTime
            );

            if (nextKf) {
                const progress = (this.currentTime - kf.time) / (nextKf.time - kf.time);
                const easedProgress = this.ease(progress, kf.easing);
                const value = this.interpolate(kf.value, nextKf.value, easedProgress);

                if (state.hasOwnProperty(kf.property)) {
                    state[kf.property] = value;
                }
            } else {
                // No next keyframe, use current value
                if (state.hasOwnProperty(kf.property)) {
                    state[kf.property] = kf.value;
                }
            }
        });
    }

    interpolate(start, end, progress) {
        if (typeof start === 'number' && typeof end === 'number') {
            return start + (end - start) * progress;
        }
        return progress < 0.5 ? start : end;
    }

    ease(t, type) {
        switch (type) {
            case 'easeIn':
                return t * t;
            case 'easeOut':
                return t * (2 - t);
            case 'easeInOut':
                return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
            case 'bounce':
                if (t < 1 / 2.75) {
                    return 7.5625 * t * t;
                } else if (t < 2 / 2.75) {
                    return 7.5625 * (t -= 1.5 / 2.75) * t + 0.75;
                } else if (t < 2.5 / 2.75) {
                    return 7.5625 * (t -= 2.25 / 2.75) * t + 0.9375;
                } else {
                    return 7.5625 * (t -= 2.625 / 2.75) * t + 0.984375;
                }
            case 'elastic':
                return Math.sin(-13 * (Math.PI / 2) * (t + 1)) * Math.pow(2, -10 * t) + 1;
            default:
                return t; // linear
        }
    }

    clear() {
        this.keyframes = [];
        this.currentTime = 0;
    }
}

// Global timeline instance
export const globalTimeline = new Timeline();

/**
 * Update timeline (called from main loop)
 */
export function updateTimeline(deltaTime = 16) {
    if (state.timelineEnabled) {
        globalTimeline.update(deltaTime);
    }
}

/**
 * Create demo timeline
 */
export function createDemoTimeline() {
    globalTimeline.clear();

    // Animate spikes
    globalTimeline.addKeyframe(0, 'spikes', 5, 'linear');
    globalTimeline.addKeyframe(2000, 'spikes', 12, 'easeInOut');
    globalTimeline.addKeyframe(4000, 'spikes', 5, 'easeInOut');

    // Animate radius
    globalTimeline.addKeyframe(0, 'outerRadius', 100, 'linear');
    globalTimeline.addKeyframe(3000, 'outerRadius', 200, 'bounce');
    globalTimeline.addKeyframe(6000, 'outerRadius', 100, 'bounce');

    // Animate glow
    globalTimeline.addKeyframe(0, 'glow', 0, 'linear');
    globalTimeline.addKeyframe(2500, 'glow', 40, 'easeIn');
    globalTimeline.addKeyframe(5000, 'glow', 0, 'easeOut');

    globalTimeline.play();
}
140 lines•4.2 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