Code Monkey home page Code Monkey logo

spxparticles's Introduction

spxparticles

Stream or a burst of image particles on HTML canvas

Simple Javascript library for generating an infinine stream or a burst of image based particles on a HTML canvas. Only visible particles remain in memory to manage memory usage and browser performance.

Please note: GIF animations on this page are running at low frame rate and does not make justice to an actual animation.

Usage

<script type="text/javascript" src="js/spxparticles.js"></script>
<script>
    window.addEventListener('DOMContentLoaded',(e) => {
    spawnSPXParticles('SPX_ParticleCanvas');
    });
</script>
<canvas id="SPX_ParticleCanvas"></canvas>

spxparticles screenshots

Example configuration #1:

var spxParticleSettings = {
    p_texture     :  '../img/fb-haha.png', 
    p_blending    :  'color-dodge',   /* (empty), screen, overlay, multiply, color-dodge... */
    emit_delay    :  30,              /* Delay between each new particle (performance warn!)  */
    emit_left     :  10,              /* Emitter zone left % */
    emit_right    :  90,              /* Emitter zone right % */
    emit_top      :  80,              /* Emitter zone top % */
    emit_bottom   :  90,              /* Emitter zone bottom % */
    zone_visible  :  false,           /* Preview emitter zone on canvas */
    gravity       :  -4,              /* Y move speed (negative: up) */
    rnd_grav_mult :  2,               /* Random speed multiplier */
    spread_x      :  0.5,             /* Dispersion value */
    wind          :  2,               /* Horizontal push force */
    wave_size     :  1,               /* Size of wavy motion */
    wave_freq     :  80,              /* Speed of wavy motion */
    p_life        :  250,             /* Maximum particle lifespan duration */
    p_rnd_life    :  20,              /* Randomize lifespan */
    p_size        :  110,             /* Particle born size in pixels */
    p_rnd_size    :  80,              /* Randomize size */
    p_size_mult   :  0.98,            /* Size multiplier, scale down/up gradually */
    p_rotation    :  0,               /* Spawn rotation (deg) */
    p_rnd_rot     :  15,              /* Randomize rotation (deg) */
    p_rot_wobble  :  true,            /* wobble back and forth? */
    p_rot_amount  :  1.2,             /* Rotation speed */
    p_rot_wofreq  :  40,              /* Wobble frequency */
    p_rot_dual    :  false,           /* both directions CW and CCW */ 
    p_opacity     :  100,             /* Opacity of a particle when born (%) */
    p_rnd_opa     :  0,               /* Randomize born opacity (%) */
    p_opa_mult    :  0.8,             /* Opacity multiplier, fade gradually */
    p_fade_start  :  150,             /* When do we start to fade out */
    p_rnd_fstart  :  20               /* Randomize fade start age */
};

Demos:

spxparticles screenshots

Demo 1 (index.html) : smiley faces rising up

Demo 2 (demo-2.html) : stars falling downwards, emitter zone visible

Demo 3 (demo-3.html): disco flashing lights

Demo 4 (demo-4.html): click handler to emit few particles

Demo 5 (demo-5.html): smoke drifting from left to right

spxparticles's People

Contributors

tuomoku avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.