Code Monkey home page Code Monkey logo

2d-canvas-image-particles's Introduction

2D Particle System using Canvas

A simple lightweight 2D particle system using Canvas.

  • Multiple particle systems can be bound to the same canvas
  • Particles speed remain the same regardless of the refreshing rate
  • Less than 10 KB
  • Refresh rate independant : particles have the same behaviour between 60hz / 144hz monitors

Check the demo page

Usage

  • Create a canvas with an id
  • Import dist/2d-canvas-image-particles.min.js
  • Create a new ParticleSystem : new ParticleSystem(canvas_id, image_path, options);

Example

<canvas id="js-canvas"></canvas>

<script src="dist/2d-canvas-image-particles.min.js"></script>
<script>
    new ParticleSystem('js-canvas', 'images/default-particle.png', {
        cursorMode: CursorMode.Zoom
    });
</script>

You can check the demo page's sources for more examples.

Options

{
    maxParticles: number,
    velocityAngle: [min, max],
    speed: [min, max],
    rotationStartAngle: [min, max],
    cursorMode: CursorMode,     // (CursorMode.Bounce, CursorMode.Zoom, CursorMode.Light, CursorMode.Follow),
    rotationMode: RotationMode, // (RotationMode.None, RotationMode.Random, RotationMode.FollowVelocity)
    rotationSpeed: [min, max],
    rotationSpeedSizeScale: number
    minimumRotationSpeed: number // if min is negative and max is positive
    tints: [new Tint('#hexColor', opacity)],
    width: [min, max],
    height: [min, max],
    addOnClickNb: number,
    density: number,
    cursorRadius: number
}

Cursor Modes

  • CursorMode.Bounce: particles will bounce off the cursor.
  • CursorMode.Zoom: the closer the cursor is, the bigger the particles are.
  • CursorMode.Light: works with Tint. Particles will enlight when cursor is close.
  • CursorMode.Follow: generates particles that are following the cursor.

Rotation Modes

  • RotationMode.None
  • RotationMode.Random
  • RotationMode.FollowVelocity: Will follow the specified velocity (use it with CursorMode.Bounce so the particles go back to their base velocity, this is used for the rain example)

Build from sources

  • npm install
  • npm run build

IE Support

  • IE9+

2d-canvas-image-particles's People

Contributors

antho-fsy avatar arkounay avatar masth0 avatar

Watchers

 avatar  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.