pencil.js
Version:
Nice modular interactive 2D drawing library.
83 lines (82 loc) • 3.1 kB
TypeScript
/**
* @module Particles
*/
/**
* Particles generator class
* <br><img src="./media/examples/particles.png" alt="particles demo"/>
* @class
* @extends Component
*/
export default class Particles extends Component {
/**
* @inheritDoc
* @param {Object} definition - Particles definition
* @return {Particles}
*/
static from(definition: any): Particles;
/**
* @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(): ParticleData;
/**
* @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: any, base: Component, generator?: OptionsGenerator, updater?: ParticlesCallback, options?: ParticleOptions);
base: Component;
generator: OptionsGenerator;
updater: ParticlesCallback;
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;
}
export type OptionsGenerator = (index: number) => any;
export type ParticlesCallback = (data: ParticleData, index: number, ...params: any[]) => any;
export type ParticleOptions = any;
export type ParticleData = {
/**
* - 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;
};
import Component from "@pencil.js/component";
import Position from "@pencil.js/position";