From 996da2a60dd2cc764bedb6d8bec3ac39fd8ca167 Mon Sep 17 00:00:00 2001 From: Sijia Wang <30830531+asd4486@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:46:08 +0100 Subject: [PATCH 1/4] improve behaviors --- src/EmitterConfig.ts | 2 +- src/behaviors/Alpha.ts | 131 +++++++++++++++++++--------------- src/behaviors/Color.ts | 141 +++++++++++++++++++------------------ src/behaviors/Scale.ts | 156 +++++++++++++++++++++-------------------- src/index.ts | 6 +- 5 files changed, 231 insertions(+), 205 deletions(-) diff --git a/src/EmitterConfig.ts b/src/EmitterConfig.ts index 68e69165..98fbee5f 100644 --- a/src/EmitterConfig.ts +++ b/src/EmitterConfig.ts @@ -112,7 +112,7 @@ export function upgradeConfig(config: EmitterConfigV2|EmitterConfigV1, art: any) // just ensure we aren't given any V3 config data if ('behaviors' in config) { - return config; + return config as EmitterConfigV3; } const out: EmitterConfigV3 = { diff --git a/src/behaviors/Alpha.ts b/src/behaviors/Alpha.ts index 60adf203..17889d47 100644 --- a/src/behaviors/Alpha.ts +++ b/src/behaviors/Alpha.ts @@ -10,10 +10,10 @@ import { BehaviorEditorConfig } from './editor/Types'; * Example config: * ```javascript * { - * type: 'alpha', - * config: { - * alpha: { - * list: [{value: 0, time: 0}, {value: 1, time: 0.25}, {value: 0, time: 1}] + * "type": "alpha", + * "config": { + * "alpha": { + * "list": [{"value": 0, "time": 0}, {"value": 1, "time": 0.25}, {"value": 0, "time": 1}] * }, * } * } @@ -21,37 +21,38 @@ import { BehaviorEditorConfig } from './editor/Types'; */ export class AlphaBehavior implements IEmitterBehavior { - public static type = 'alpha'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'alpha'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - constructor(config: { - /** - * Transparency of the particles from 0 (transparent) to 1 (opaque) - */ - alpha: ValueList; - }) - { - this.list = new PropertyList(false); - this.list.reset(PropertyNode.createList(config.alpha)); - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + constructor(config: { + /** + * Transparency of the particles from 0 (transparent) to 1 (opaque) + */ + alpha: ValueList; + }) + { + this.list = new PropertyList(false); + this.list.reset(PropertyNode.createList(config.alpha)); + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - next.alpha = this.list.first.value; - next = next.next; - } - } + while (next) + { + next.config.originAlpha = next.config.originAlpha ?? 1; + next.alpha = next.config.originAlpha * this.list.first.value; + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.alpha = this.list.interpolate(particle.agePercent); - } + updateParticle(particle: Particle): void + { + particle.alpha = this.list.interpolate(particle.agePercent); + } } /** @@ -60,38 +61,56 @@ export class AlphaBehavior implements IEmitterBehavior * Example config: * ```javascript * { - * type: 'alphaStatic', - * config: { - * alpha: 0.75, + * "type": "alphaStatic", + * "config": { + * "alpha": 0.75, * } * } * ``` + * or + * ```javascript + * { + * "type": "alphaStatic", + * "config": { + * "alpha": {"min": 0.5, "max": 1} + * } + * } */ + +type AlphaData = { + min: number; + max: number; +}; export class StaticAlphaBehavior implements IEmitterBehavior { - public static type = 'alphaStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'alphaStatic'; + public static editorConfig: BehaviorEditorConfig = null; + + public order = BehaviorOrder.Normal; + private value: number | AlphaData; + constructor(config: { + /** + * Transparency of the particles from 0 (transparent) to 1 (opaque) + */ + alpha: number | AlphaData; + }) + { + this.value = config.alpha; + } - public order = BehaviorOrder.Normal; - private value: number; - constructor(config: { - /** - * Transparency of the particles from 0 (transparent) to 1 (opaque) - */ - alpha: number; - }) - { - this.value = config.alpha; - } + initParticles(first: Particle): void + { + let next = first; - initParticles(first: Particle): void - { - let next = first; + while (next) + { + const val + = typeof this.value === 'number' + ? this.value + : (Math.random() * (this.value.max - this.value.min)) + this.value.min; - while (next) - { - next.alpha = this.value; - next = next.next; - } - } + next.config.originAlpha = next.alpha = Math.min(val, 1); + next = next.next; + } + } } diff --git a/src/behaviors/Color.ts b/src/behaviors/Color.ts index ed13e7b1..c302feeb 100644 --- a/src/behaviors/Color.ts +++ b/src/behaviors/Color.ts @@ -11,10 +11,10 @@ import { BehaviorEditorConfig } from './editor/Types'; * Example config: * ```javascript * { - * type: 'color', - * config: { - * color: { - * list: [{value: '#ff0000' time: 0}, {value: '#00ff00', time: 0.5}, {value: '#0000ff', time: 1}] + * "type": "color", + * "config": { + * "color": { + * "list": [{"value": "#ff0000", "time": 0}, {"value": "#00ff00", "time": 0.5}, {"value": "#0000ff", "time": 1}] * }, * } * } @@ -22,90 +22,93 @@ import { BehaviorEditorConfig } from './editor/Types'; */ export class ColorBehavior implements IEmitterBehavior { - public static type = 'color'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'color'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - constructor(config: { - /** - * Color of the particles as 6 digit hex codes. - */ - color: ValueList; - }) - { - this.list = new PropertyList(true); - this.list.reset(PropertyNode.createList(config.color)); - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + constructor(config: { + /** + * Color of the particles as 6 digit hex codes. + */ + color: ValueList; + }) + { + this.list = new PropertyList(true); + this.list.reset(PropertyNode.createList(config.color)); + } - initParticles(first: Particle): void - { - let next = first; - const color = this.list.first.value; - const tint = combineRGBComponents(color.r, color.g, color.b); + initParticles(first: Particle): void + { + let next = first; + const color = this.list.first.value; + const tint = combineRGBComponents(color.r, color.g, color.b); - while (next) - { - next.tint = tint; - next = next.next; - } - } + while (next) + { + next.tint = tint; + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.tint = this.list.interpolate(particle.agePercent); - } + updateParticle(particle: Particle): void + { + particle.tint = this.list.interpolate(particle.agePercent); + } } /** - * A Color behavior that applies a single color to the particle's tint property at initialization. + * A Color behavior that applies a randomly picked color to the particle's tint property at initialization. * * Example config: * ```javascript * { - * type: 'colorStatic', - * config: { - * color: '#ffff00', + * "type": "colorStatic", + * "config": { + * "color": ["#ffffff", "#ffff00"], * } * } * ``` */ export class StaticColorBehavior implements IEmitterBehavior { - public static type = 'colorStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'colorStatic'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private value: number; - constructor(config: { - /** - * Color of the particles as 6 digit hex codes. - */ - color: string; - }) - { - let color = config.color; + public order = BehaviorOrder.Spawn; + private values: number[] = []; + constructor(config: { + /** + * Color of the particles as 6 digit hex codes. + */ + color: string | string[]; + }) + { + const colors + = config.color instanceof Array ? config.color : [config.color]; - if (color.charAt(0) === '#') - { - color = color.substr(1); - } - else if (color.indexOf('0x') === 0) - { - color = color.substr(2); - } + colors.forEach((color) => + { + if (color.charAt(0) === '#') + { + color = color.substring(1); + } + else if (color.indexOf('0x') === 0) + { + color = color.substring(2); + } + this.values.push(parseInt(color, 16)); + }); + } - this.value = parseInt(color, 16); - } + initParticles(first: Particle): void + { + let next = first; - initParticles(first: Particle): void - { - let next = first; - - while (next) - { - next.tint = this.value; - next = next.next; - } - } + while (next) + { + next.tint = this.values[Math.round(Math.random() * this.values.length)]; + next = next.next; + } + } } diff --git a/src/behaviors/Scale.ts b/src/behaviors/Scale.ts index b892d06c..3a93435e 100644 --- a/src/behaviors/Scale.ts +++ b/src/behaviors/Scale.ts @@ -10,61 +10,66 @@ import { BehaviorEditorConfig } from './editor/Types'; * Example config: * ```javascript * { - * type: 'scale', - * config: { - * scale: { - * list: [{value: 0, time: 0}, {value: 1, time: 0.25}, {value: 0, time: 1}], - * isStepped: true + * "type": "scale", + * "config": { + * "scale": { + * "list": [{"value": 0, "time": 0}, {"value": 1, "time": 0.25}, {"value": 0, "time": 1}], + * "isStepped": "true" * }, - * minMult: 0.5 + * "minMult": 0.5 * } * } * ``` */ export class ScaleBehavior implements IEmitterBehavior { - public static type = 'scale'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'scale'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - private minMult: number; - constructor(config: { - /** - * Scale of the particles, with a minimum value of 0 - */ - scale: ValueList; - /** - * A value between minimum scale multipler and 1 is randomly - * generated and multiplied with each scale value to provide the actual scale for each particle. - */ - minMult: number; - }) - { - this.list = new PropertyList(false); - this.list.reset(PropertyNode.createList(config.scale)); - this.minMult = config.minMult ?? 1; - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + private minMult: number; + constructor(config: { + /** + * Scale of the particles, with a minimum value of 0 + */ + scale: ValueList; + /** + * A value between minimum scale multipler and 1 is randomly + * generated and multiplied with each scale value to provide the actual scale for each particle. + */ + minMult: number; + }) + { + this.list = new PropertyList(false); + this.list.reset(PropertyNode.createList(config.scale)); + this.minMult = config.minMult ?? 1; + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - const mult = (Math.random() * (1 - this.minMult)) + this.minMult; + while (next) + { + const mult = Math.random() * (1 - this.minMult) + this.minMult; - next.config.scaleMult = mult; - next.scale.x = next.scale.y = this.list.first.value * mult; + next.config.scaleMult = mult; + next.config.originScale = next.config.originScale ?? 1; + next.scale.x = next.scale.y + = next.config.originScale * this.list.first.value * mult; - next = next.next; - } - } + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.scale.x = particle.scale.y = this.list.interpolate(particle.agePercent) * particle.config.scaleMult; - } + updateParticle(particle: Particle): void + { + particle.scale.x = particle.scale.y + = this.list.interpolate(particle.agePercent) + * particle.config.scaleMult + * particle.config.originScale; + } } /** @@ -73,48 +78,47 @@ export class ScaleBehavior implements IEmitterBehavior * Example config: * ```javascript * { - * type: 'scaleStatic', - * config: { - * min: 0.25, - * max: 0.75, + * "type": "scaleStatic", + * "config": { + * "min": 0.25, + * "max": 0.75, * } * } * ``` */ export class StaticScaleBehavior implements IEmitterBehavior { - public static type = 'scaleStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'scaleStatic'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private min: number; - private max: number; - constructor(config: { - /** - * Minimum scale of the particles, with a minimum value of 0 - */ - min: number; - /** - * Maximum scale of the particles, with a minimum value of 0 - */ - max: number; - }) - { - this.min = config.min; - this.max = config.max; - } + public order = BehaviorOrder.Spawn; + private min: number; + private max: number; + constructor(config: { + /** + * Minimum scale of the particles, with a minimum value of 0 + */ + min: number; + /** + * Maximum scale of the particles, with a minimum value of 0 + */ + max: number; + }) + { + this.min = config.min; + this.max = config.max; + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - const scale = (Math.random() * (this.max - this.min)) + this.min; + while (next) + { + const scale = Math.random() * (this.max - this.min) + this.min; - next.scale.x = next.scale.y = scale; - - next = next.next; - } - } + next.config.originScale = next.scale.x = next.scale.y = scale; + next = next.next; + } + } } diff --git a/src/index.ts b/src/index.ts index 16c06cfb..3300d886 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,8 @@ import { Emitter } from './Emitter'; import * as behaviors from './behaviors'; Emitter.registerBehavior(behaviors.AccelerationBehavior); -Emitter.registerBehavior(behaviors.AlphaBehavior); Emitter.registerBehavior(behaviors.StaticAlphaBehavior); +Emitter.registerBehavior(behaviors.AlphaBehavior); Emitter.registerBehavior(behaviors.RandomAnimatedTextureBehavior); Emitter.registerBehavior(behaviors.SingleAnimatedTextureBehavior); Emitter.registerBehavior(behaviors.BlendModeBehavior); @@ -14,11 +14,11 @@ Emitter.registerBehavior(behaviors.OrderedTextureBehavior); Emitter.registerBehavior(behaviors.PathBehavior); Emitter.registerBehavior(behaviors.PointSpawnBehavior); Emitter.registerBehavior(behaviors.RandomTextureBehavior); -Emitter.registerBehavior(behaviors.RotationBehavior); Emitter.registerBehavior(behaviors.StaticRotationBehavior); +Emitter.registerBehavior(behaviors.RotationBehavior); Emitter.registerBehavior(behaviors.NoRotationBehavior); -Emitter.registerBehavior(behaviors.ScaleBehavior); Emitter.registerBehavior(behaviors.StaticScaleBehavior); +Emitter.registerBehavior(behaviors.ScaleBehavior); Emitter.registerBehavior(behaviors.ShapeSpawnBehavior); Emitter.registerBehavior(behaviors.SingleTextureBehavior); Emitter.registerBehavior(behaviors.SpeedBehavior); From aae830d844ab79f82bf23db5a2e4d561d30e5740 Mon Sep 17 00:00:00 2001 From: Sijia Wang <30830531+asd4486@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:47:08 +0100 Subject: [PATCH 2/4] add confetti/improve bubbles exemple --- docs/examples/bubbles.html | 84 +++++++++++-------- docs/examples/confetti.html | 122 ++++++++++++++++++++++++++++ docs/examples/images/confetti-0.png | Bin 0 -> 117 bytes docs/examples/images/confetti-1.png | Bin 0 -> 341 bytes docs/examples/images/confetti-2.png | Bin 0 -> 291 bytes 5 files changed, 170 insertions(+), 36 deletions(-) create mode 100644 docs/examples/confetti.html create mode 100644 docs/examples/images/confetti-0.png create mode 100644 docs/examples/images/confetti-1.png create mode 100644 docs/examples/images/confetti-2.png diff --git a/docs/examples/bubbles.html b/docs/examples/bubbles.html index 97306446..bcc8f0ed 100644 --- a/docs/examples/bubbles.html +++ b/docs/examples/bubbles.html @@ -1,11 +1,11 @@ - - + + Bubbles - - + + @@ -13,14 +13,12 @@ -
Click Anywhere
- \ No newline at end of file + diff --git a/docs/examples/confetti.html b/docs/examples/confetti.html new file mode 100644 index 00000000..fb25bcaf --- /dev/null +++ b/docs/examples/confetti.html @@ -0,0 +1,122 @@ + + + + + + Bubbles + + + + + + + + + + + +
+
Click Anywhere
+ + + + diff --git a/docs/examples/images/confetti-0.png b/docs/examples/images/confetti-0.png new file mode 100644 index 0000000000000000000000000000000000000000..ce64b8667c37bf486ecb34fe16b88ab8ede875c4 GIT binary patch literal 117 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnH3?%tPCZz)@o&cW^S0Mc#1}qL(uK@CyOM?7@ z8GgL|vBGd2kSprx;us=vIXNNW4^ZKKwzfdFFgAvkhWAQlM0`$-?wg^wmJ!(|*m(7aR{t%FK4l z{_^FOMT9|qP@Dad?8#LJxq7WMSSCoT)D>DXhAq>dyx(ePJOi^pb>w*?Td(Sz{S~@F sIbO$=`KK}`2Dcr{+bx}b@_sF&o3-k?KO%9jfSzISboFyt=akR{05?0K1poj5 literal 0 HcmV?d00001 diff --git a/docs/examples/images/confetti-2.png b/docs/examples/images/confetti-2.png new file mode 100644 index 0000000000000000000000000000000000000000..6f0fa46e13c1646490290fa1cba9b7ec5e3d9343 GIT binary patch literal 291 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv^#Gp`S0MeL2(Zr9%Mz%RrzFTP znBl&H!21Og63+J7EQznFgTgQf(J;;Dn!;9y<0%PKW12QR%lO1H!0~(l^wO2VXHS?}&Fm~o$b)c|K zBBXIKkL?O3b%~k));@zdj?5BF5>W;`M>mLFPE=dL)Gm1=fR)K$@A(PMXYAV~TV^!& zNb=4QJet5J?9t}BPU}d#XU7Zk{%@9>L?_8GtT(bcyj@31ALvvDPgg&ebxsLQ0Fc9S AhyVZp literal 0 HcmV?d00001 From 6e37f5a76bb3c02471d779ee95b740b787c22b50 Mon Sep 17 00:00:00 2001 From: Sijia Wang <30830531+asd4486@users.noreply.github.com> Date: Fri, 17 Nov 2023 20:04:48 +0100 Subject: [PATCH 3/4] fix confetti.index title --- docs/examples/confetti.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/confetti.html b/docs/examples/confetti.html index fb25bcaf..145a82ce 100644 --- a/docs/examples/confetti.html +++ b/docs/examples/confetti.html @@ -3,8 +3,8 @@ - Bubbles - + Confetti + From ab515cdaf8a144ea148cee0dc6c976f5ae023d27 Mon Sep 17 00:00:00 2001 From: Sijia Wang <30830531+asd4486@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:37:14 +0100 Subject: [PATCH 4/4] fix code format --- README.md | 1 + docs/examples/index.html | 1 + src/behaviors/Alpha.ts | 112 +++++++++++++++---------------- src/behaviors/Color.ts | 128 +++++++++++++++++------------------ src/behaviors/Scale.ts | 140 +++++++++++++++++++-------------------- 5 files changed, 192 insertions(+), 190 deletions(-) diff --git a/README.md b/README.md index 4dd186c9..e504883f 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ npm install @pixi/particle-emitter * [Snow](https://pixijs.github.io/particle-emitter/examples/snow.html) * [Sparks](https://pixijs.github.io/particle-emitter/examples/sparks.html) * [Fountain](https://pixijs.github.io/particle-emitter/examples/fountain.html) +* [Confetti](https://pixijs.github.io/particle-emitter/examples/confetti.html) * [Animated Coins](https://pixijs.github.io/particle-emitter/examples/coins.html) * [Animated Bubbles](https://pixijs.github.io/particle-emitter/examples/animatedBubbles.html) * [Spaceship Destruction - Ordered Art](https://pixijs.github.io/particle-emitter/examples/spaceshipDestruction.html) diff --git a/docs/examples/index.html b/docs/examples/index.html index 5da23d87..1c235391 100644 --- a/docs/examples/index.html +++ b/docs/examples/index.html @@ -35,6 +35,7 @@

Emitter Examples

  • Snow
  • Sparks
  • Fountain
  • +
  • Confetti
  • Animated Coins
  • Animated Bubbles
  • Spaceship Destruction
  • diff --git a/src/behaviors/Alpha.ts b/src/behaviors/Alpha.ts index 17889d47..3de058d1 100644 --- a/src/behaviors/Alpha.ts +++ b/src/behaviors/Alpha.ts @@ -21,38 +21,38 @@ import { BehaviorEditorConfig } from './editor/Types'; */ export class AlphaBehavior implements IEmitterBehavior { - public static type = 'alpha'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'alpha'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - constructor(config: { - /** - * Transparency of the particles from 0 (transparent) to 1 (opaque) - */ - alpha: ValueList; - }) - { - this.list = new PropertyList(false); - this.list.reset(PropertyNode.createList(config.alpha)); - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + constructor(config: { + /** + * Transparency of the particles from 0 (transparent) to 1 (opaque) + */ + alpha: ValueList; + }) + { + this.list = new PropertyList(false); + this.list.reset(PropertyNode.createList(config.alpha)); + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - next.config.originAlpha = next.config.originAlpha ?? 1; - next.alpha = next.config.originAlpha * this.list.first.value; - next = next.next; - } - } + while (next) + { + next.config.originAlpha = next.config.originAlpha ?? 1; + next.alpha = next.config.originAlpha * this.list.first.value; + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.alpha = this.list.interpolate(particle.agePercent); - } + updateParticle(particle: Particle): void + { + particle.alpha = this.list.interpolate(particle.agePercent); + } } /** @@ -78,39 +78,39 @@ export class AlphaBehavior implements IEmitterBehavior */ type AlphaData = { - min: number; - max: number; + min: number; + max: number; }; export class StaticAlphaBehavior implements IEmitterBehavior { - public static type = 'alphaStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'alphaStatic'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private value: number | AlphaData; - constructor(config: { - /** - * Transparency of the particles from 0 (transparent) to 1 (opaque) - */ - alpha: number | AlphaData; - }) - { - this.value = config.alpha; - } + public order = BehaviorOrder.Normal; + private value: number | AlphaData; + constructor(config: { + /** + * Transparency of the particles from 0 (transparent) to 1 (opaque) + */ + alpha: number | AlphaData; + }) + { + this.value = config.alpha; + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - const val - = typeof this.value === 'number' - ? this.value - : (Math.random() * (this.value.max - this.value.min)) + this.value.min; + while (next) + { + const val + = typeof this.value === 'number' + ? this.value + : (Math.random() * (this.value.max - this.value.min)) + this.value.min; - next.config.originAlpha = next.alpha = Math.min(val, 1); - next = next.next; - } - } + next.config.originAlpha = next.alpha = Math.min(val, 1); + next = next.next; + } + } } diff --git a/src/behaviors/Color.ts b/src/behaviors/Color.ts index c302feeb..0e41f63f 100644 --- a/src/behaviors/Color.ts +++ b/src/behaviors/Color.ts @@ -22,39 +22,39 @@ import { BehaviorEditorConfig } from './editor/Types'; */ export class ColorBehavior implements IEmitterBehavior { - public static type = 'color'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'color'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - constructor(config: { - /** - * Color of the particles as 6 digit hex codes. - */ - color: ValueList; - }) - { - this.list = new PropertyList(true); - this.list.reset(PropertyNode.createList(config.color)); - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + constructor(config: { + /** + * Color of the particles as 6 digit hex codes. + */ + color: ValueList; + }) + { + this.list = new PropertyList(true); + this.list.reset(PropertyNode.createList(config.color)); + } - initParticles(first: Particle): void - { - let next = first; - const color = this.list.first.value; - const tint = combineRGBComponents(color.r, color.g, color.b); + initParticles(first: Particle): void + { + let next = first; + const color = this.list.first.value; + const tint = combineRGBComponents(color.r, color.g, color.b); - while (next) - { - next.tint = tint; - next = next.next; - } - } + while (next) + { + next.tint = tint; + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.tint = this.list.interpolate(particle.agePercent); - } + updateParticle(particle: Particle): void + { + particle.tint = this.list.interpolate(particle.agePercent); + } } /** @@ -72,43 +72,43 @@ export class ColorBehavior implements IEmitterBehavior */ export class StaticColorBehavior implements IEmitterBehavior { - public static type = 'colorStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'colorStatic'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Spawn; - private values: number[] = []; - constructor(config: { - /** - * Color of the particles as 6 digit hex codes. - */ - color: string | string[]; - }) - { - const colors - = config.color instanceof Array ? config.color : [config.color]; + public order = BehaviorOrder.Spawn; + private values: number[] = []; + constructor(config: { + /** + * Color of the particles as 6 digit hex codes. + */ + color: string | string[]; + }) + { + const colors + = config.color instanceof Array ? config.color : [config.color]; - colors.forEach((color) => - { - if (color.charAt(0) === '#') - { - color = color.substring(1); - } - else if (color.indexOf('0x') === 0) - { - color = color.substring(2); - } - this.values.push(parseInt(color, 16)); - }); - } + colors.forEach((color) => + { + if (color.charAt(0) === '#') + { + color = color.substring(1); + } + else if (color.indexOf('0x') === 0) + { + color = color.substring(2); + } + this.values.push(parseInt(color, 16)); + }); + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - next.tint = this.values[Math.round(Math.random() * this.values.length)]; - next = next.next; - } - } + while (next) + { + next.tint = this.values[Math.round(Math.random() * this.values.length)]; + next = next.next; + } + } } diff --git a/src/behaviors/Scale.ts b/src/behaviors/Scale.ts index 3a93435e..df33ac60 100644 --- a/src/behaviors/Scale.ts +++ b/src/behaviors/Scale.ts @@ -23,53 +23,53 @@ import { BehaviorEditorConfig } from './editor/Types'; */ export class ScaleBehavior implements IEmitterBehavior { - public static type = 'scale'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'scale'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Normal; - private list: PropertyList; - private minMult: number; - constructor(config: { - /** - * Scale of the particles, with a minimum value of 0 - */ - scale: ValueList; - /** - * A value between minimum scale multipler and 1 is randomly - * generated and multiplied with each scale value to provide the actual scale for each particle. - */ - minMult: number; - }) - { - this.list = new PropertyList(false); - this.list.reset(PropertyNode.createList(config.scale)); - this.minMult = config.minMult ?? 1; - } + public order = BehaviorOrder.Normal; + private list: PropertyList; + private minMult: number; + constructor(config: { + /** + * Scale of the particles, with a minimum value of 0 + */ + scale: ValueList; + /** + * A value between minimum scale multipler and 1 is randomly + * generated and multiplied with each scale value to provide the actual scale for each particle. + */ + minMult: number; + }) + { + this.list = new PropertyList(false); + this.list.reset(PropertyNode.createList(config.scale)); + this.minMult = config.minMult ?? 1; + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - const mult = Math.random() * (1 - this.minMult) + this.minMult; + while (next) + { + const mult = (Math.random() * (1 - this.minMult)) + this.minMult; - next.config.scaleMult = mult; - next.config.originScale = next.config.originScale ?? 1; - next.scale.x = next.scale.y - = next.config.originScale * this.list.first.value * mult; + next.config.scaleMult = mult; + next.config.originScale = next.config.originScale ?? 1; + next.scale.x = next.scale.y + = next.config.originScale * this.list.first.value * mult; - next = next.next; - } - } + next = next.next; + } + } - updateParticle(particle: Particle): void - { - particle.scale.x = particle.scale.y - = this.list.interpolate(particle.agePercent) - * particle.config.scaleMult - * particle.config.originScale; - } + updateParticle(particle: Particle): void + { + particle.scale.x = particle.scale.y + = this.list.interpolate(particle.agePercent) + * particle.config.scaleMult + * particle.config.originScale; + } } /** @@ -88,37 +88,37 @@ export class ScaleBehavior implements IEmitterBehavior */ export class StaticScaleBehavior implements IEmitterBehavior { - public static type = 'scaleStatic'; - public static editorConfig: BehaviorEditorConfig = null; + public static type = 'scaleStatic'; + public static editorConfig: BehaviorEditorConfig = null; - public order = BehaviorOrder.Spawn; - private min: number; - private max: number; - constructor(config: { - /** - * Minimum scale of the particles, with a minimum value of 0 - */ - min: number; - /** - * Maximum scale of the particles, with a minimum value of 0 - */ - max: number; - }) - { - this.min = config.min; - this.max = config.max; - } + public order = BehaviorOrder.Spawn; + private min: number; + private max: number; + constructor(config: { + /** + * Minimum scale of the particles, with a minimum value of 0 + */ + min: number; + /** + * Maximum scale of the particles, with a minimum value of 0 + */ + max: number; + }) + { + this.min = config.min; + this.max = config.max; + } - initParticles(first: Particle): void - { - let next = first; + initParticles(first: Particle): void + { + let next = first; - while (next) - { - const scale = Math.random() * (this.max - this.min) + this.min; + while (next) + { + const scale = (Math.random() * (this.max - this.min)) + this.min; - next.config.originScale = next.scale.x = next.scale.y = scale; - next = next.next; - } - } + next.config.originScale = next.scale.x = next.scale.y = scale; + next = next.next; + } + } }