0.0.1 • Published 5 years ago

particles.ts v0.0.1

Weekly downloads
4
License
MIT
Repository
-
Last release
5 years ago

Particles

Port of Vincent Garreau' particles.js which was originally a port of Vincent Garreau' particles.js, written in Typescript with added features.

Instalation

$ npm install particles.ts

Or just download the minified script and add it in your HTML:

<script src="particles.min.js"></script>

Usage

The particle class takes 2 optional arguments: id is the element string, and config which is an object with the settings.

particles = new Particles('id', {/*configuration object*/}).start();

You can set only the values you want to change in the configuration object. For example the example below will only change the particles color and use the default settings for everything else.

particles = new Particles('id', {
  particles: {
    color: {
      value: '#FF0000'
    }
  }
})

particles.start()

Configuration

The default config object looks something like this

settings = {
  particles: {
    number: {
      value: 100,
      density: {
        enable: true,
        value_area: 800
      }
    },
    color: {
      value: '#ffffff'
    },
    shape: {
      type: 'circle',
      stroke: {
        width: 0,
        color: '#FFFFFF'
      },
      polygon: {
        nb_sides: 5
      },
      character: {
        value: 'P',
        font: 'arial',
        style: 'normal',
        weight: 'normal',
      },
      image: {
        src: '',
        width: 100,
        height: 100
      }
    },
    opacity: {
      value: 1,
      random: false,
      anim: {
        enable: false,
        speed: 2,
        opacity_min: 0,
        sync: false
      }
    },
    size: {
      value: 10,
      random: false,
      anim: {
        enable: false,
        speed: 20,
        size_min: 0,
        sync: false
      }
    },
    line_linked: {
      enable: true,
      distance: 100,
      color: '#FFFFFF',
      opacity: 1,
      width: 1
    },
    move: {
      enable: true,
      speed: 6,
      direction: 'none',
      random: false,
      straight: false,
      out_mode: 'out',
      bounce: false,
      parallax: false,
      attract: {
        enable: false,
        rotateX: 3000,
        rotateY: 3000
      }
    }
  },
  interactivity: {
    detect_on: 'canvas',
    events: {
      onhover: {
        enable: true,
        mode: 'grab'
      },
      onclick: {
        enable: true,
        mode: 'push'
      },
      resize: true
    },
    modes: {
      grab: {
        distance: 100,
        line_linked: {
          opacity: 1
        },
        outer_shape: {
          enable: false,
          type: 'inherit',
          size: 20,
          stroke: {
            width: 'inherit',
            color: 'inherit'
          },
        }
      },
      bubble: {
        distance: 100,
        size: 40,
        duration: 0.4,
        opacity: 8,
        speed: 3
      },
      repulse: {
        distance: 200,
        strength: 100,
        duration: 0.4
      },
      push: {
        particles_nb: 4
      },
      remove: {
        particles_nb: 2
      }
    }
  },
  retina_detect: false
};
keytypedefaultnotes
particles.number.valuenumber100
particles.number.density.enablebooleantrue
particles.number.density.value_areanumber800
particles.color.valuestring: Hex or "random" string[]: Hex#FFFFFFExamples: "#b61924" ["#b61924", "#333333", "999999"] "random"
particles.shape.typestring string[]"circle"Possible values: "circle" "edge" "square" "triangle" "polygon" "star" "character" "char" "image"
particles.shape.stroke.widthnumber0
particles.shape.stroke.colorstring"#FF0000"
particles.shape.polygon.nb_slidesnumber5
particles.shape.character.valuestring string[]"P"
particles.shape.character.fontstring"arial"
particles.shape.character.stylestring"normal"Possible values are the same as in the CSS font-style property
particles.shape.character.weightstring"normal"Possible values are the same as in the CSS font-weight property
particles.shape.image.srcstring"particle.png"
particles.shape.image.widthnumber100
particles.shape.image.heightnumber100
particles.opacity.valuenumber10 to 1
particles.opacity.randombooleanfalse
particles.opacity.anim.enablebooleanfalse
particles.opacity.anim.speednumber2
particles.opacity.anim.opacity_minnumber00 to 1
particles.opacity.anim.syncbooleanfalse
particles.size.valuenumber10
particles.size.randombooleanfalse
particles.size.anim.enablebooleanfalse
particles.size.anim.speednumber20
particles.size.anim.size_minnumber0
particles.size.anim.syncbooleanfalse
particles.line_linked.enablebooleantrue
particles.line_linked.distancenumber100
particles.line_linked.colorstring#FFFFFF
particles.line_linked.opacitynumber10 to 1
particles.line_linked.widthnumber1
particles.move.enablebooleantrue
particles.move.speednumber6
particles.move.directionstring"none"Possible values: "none" "top" "top-right" "right" "bottom-right" "bottom" "bottom-left" "left" "top-left"
particles.move.randombooleanfalse
particles.move.straightbooleanfalse
particles.move.out_modestring"out"Possible values: "out" "bounce"
particles.move.parallaxbooleanfalse
particles.move.bouncebooleanfalseBounce between particles
particles.move.attract.enablebooleanfalse
particles.move.attract.rotateXnumber3000
particles.move.attract.rotateYnumber3000
interactivity.detect_onstring"canvas"Possible values: "canvas" "window"
interactivity.events.onhover.enablebooleantrue
interactivity.events.onhover.modestring string[]"grab"Possible values: "grab" "bubble" "repulse"
interactivity.events.onclick.enablebooleantrue
interactivity.events.onclick.modestring string[]"push"Possible values: "push" "remove" "bubble" "repulse"
interactivity.events.resizebooleantrue
interactivity.events.modes.grab.distancenumber100
interactivity.events.modes.grab.line_linked.opacitynumber0.750 to 1
interactivity.events.modes.grab.outer_shape.enablebooleanfalse
interactivity.events.modes.grab.outer_shape.typestring"inherit""inherit" will use particles.line_linked values Possible values: "inherit" "circle" "edge" "square" "triangle" "polygon" "star" "character" "char"
interactivity.events.modes.grab.outer_shape.sizenumber20Added to the particles' size
interactivity.events.modes.grab.outer_shape.stroke.widthstring number"inherit""inherit" will use particles.line_linked values
interactivity.events.modes.grab.outer_shape.stroke.colorstring"inherit""inherit" will use particles.line_linked values
interactivity.events.modes.bubble.distancenumber100
interactivity.events.modes.bubble.sizenumber40
interactivity.events.modes.bubble.durationnumber0.4in seconds
interactivity.events.modes.repulse.strengthnumber100
interactivity.events.modes.repulse.distancenumber200
interactivity.events.modes.repulse.durationnumber0.4in seconds
interactivity.events.modes.push.particles_nbnumber4
interactivity.events.modes.push.particles_nbnumber2
retina_detectbooleanfalse