UNPKG

pencil.js

Version:

Nice modular interactive 2D drawing library.

136 lines (135 loc) 4.58 kB
/** * @module Particles */ /** * Particles generator class * <br><img src="./media/examples/particles.png" alt="particles demo"/> * @class * @extends {module:Component} */ export default class Particles { /** * @inheritDoc * @param {Object} definition - Particles definition * @return {Particles} */ static from(definition: any): Particles; /** * @typedef {Object} ParticleOptions * @extends ComponentOptions * @prop {Number} [frequency=1] - Frequency of emission (randomized) * @prop {Number|Array<Number>} [emit] - Number or range of particles emitted * @prop {Array} [args] - Arguments passed to the generator function */ /** * @type {ParticleOptions} */ static get defaultOptions(): any; /** * @typedef {Object} ParticleData * @prop {Position} [position=new Position()] - Position of the particle * @prop {Number} [rotation=0] - Rotation applied to the particle * @prop {Number|Position} [scale=1] - Scaling ratio or a pair of value for horizontal and vertical scaling * @prop {Number} [ttl] - Time to live, number of frames the particle is displayed. This number will be decremented and the data removed when it reach 0 */ /** * @type {ParticleData} */ static get defaultData(): { /** * - Position of the particle */ position?: Position; /** * - Rotation applied to the particle */ rotation?: number; /** * - Scaling ratio or a pair of value for horizontal and vertical scaling */ scale?: number | Position; /** * - Time to live, number of frames the particle is displayed. This number will be decremented and the data removed when it reach 0 */ ttl?: number; }; /** * @callback OptionsGenerator * @param {Number} index - Index of the particle * @return ParticleData */ /** * @callback ParticlesCallback * @param {ParticleData} data - One particle data * @param {Number} index - Index of the particle * @param {...*} params - Additional parameters */ /** * Particles constructor * @param {PositionDefinition} positionDefinition - Origin for all particles * @param {Component} base - Blueprint for each particle * @param {OptionsGenerator} [generator] - Initialization function for all particles data * @param {ParticlesCallback} [updater] - Function called on each particle draw (should not be computation intensive) * @param {ParticleOptions} [options] - */ constructor(positionDefinition: PositionDefinition, base: Component, generator?: (index: number) => Particles, updater?: (data: { /** * - Position of the particle */ position?: Position; /** * - Rotation applied to the particle */ rotation?: number; /** * - Scaling ratio or a pair of value for horizontal and vertical scaling */ scale?: number | Position; /** * - Time to live, number of frames the particle is displayed. This number will be decremented and the data removed when it reach 0 */ ttl?: number; }, index: number, ...params: any[]) => Particles, options?: any); base: Component; generator: (index: number) => Particles; updater: (data: { /** * - Position of the particle */ position?: Position; /** * - Rotation applied to the particle */ rotation?: number; /** * - Scaling ratio or a pair of value for horizontal and vertical scaling */ scale?: number | Position; /** * - Time to live, number of frames the particle is displayed. This number will be decremented and the data removed when it reach 0 */ ttl?: number; }, index: number, ...params: any[]) => Particles; data: any[]; /** * Create new particles * @param {Number} number - Number of particles to generate * @param {...*} params - Additional parameters for the generator function * @return {Particles} Itself */ generate(number: number, ...params: any[]): Particles; /** * @inheritDoc */ trace(path: any): this; /** * @inheritDoc */ isHover(): boolean; /** * @inheritDoc */ toJSON(): any; } import Component from "@pencil.js/component"; import Position from "@pencil.js/position";