Skip to content

Commit

Permalink
feat: added decay to all animations
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed May 9, 2022
1 parent a825299 commit 954858e
Show file tree
Hide file tree
Showing 28 changed files with 374 additions and 257 deletions.
Expand Up @@ -38,6 +38,7 @@ export class StrokeOptionsEditor extends EditorBase {
enable: false,
offset: { max: 0, min: 0 },
speed: 0,
decay: 0,
sync: false,
},
};
Expand Down
1 change: 1 addition & 0 deletions engine/src/Core/Interfaces/IParticleValueAnimation.ts
Expand Up @@ -7,6 +7,7 @@ export interface IParticleValueAnimation<T> {
enable: boolean;
status?: AnimationStatus;
velocity?: number;
decay?: number;
value: T;
loops?: number;
maxLoops?: number;
Expand Down
6 changes: 3 additions & 3 deletions engine/src/Core/Particle.ts
Expand Up @@ -352,7 +352,8 @@ export class Particle implements IParticle {

/* size */
const sizeOptions = this.options.size,
sizeRange = sizeOptions.value;
sizeRange = sizeOptions.value,
sizeAnimation = sizeOptions.animation;

this.size = {
enable: sizeOptions.animation.enable,
Expand All @@ -363,10 +364,9 @@ export class Particle implements IParticle {
maxLoops: getRangeValue(sizeOptions.animation.count),
};

const sizeAnimation = sizeOptions.animation;

if (sizeAnimation.enable) {
this.size.status = AnimationStatus.increasing;
this.size.decay = 1 - getRangeValue(sizeAnimation.decay);

switch (sizeAnimation.startValue) {
case StartValueType.min:
Expand Down
217 changes: 0 additions & 217 deletions engine/src/Options/Classes/AnimatableGradient.ts

This file was deleted.

6 changes: 6 additions & 0 deletions engine/src/Options/Classes/AnimationOptions.ts
Expand Up @@ -8,12 +8,14 @@ export class AnimationOptions implements IAnimation, IOptionLoader<IAnimation> {
count: RangeValue;
enable: boolean;
speed: RangeValue;
decay: RangeValue;
sync: boolean;

constructor() {
this.count = 0;
this.enable = false;
this.speed = 1;
this.decay = 0;
this.sync = false;
}

Expand All @@ -34,6 +36,10 @@ export class AnimationOptions implements IAnimation, IOptionLoader<IAnimation> {
this.speed = setRangeValue(data.speed);
}

if (data.decay !== undefined) {
this.decay = setRangeValue(data.decay);
}

if (data.sync !== undefined) {
this.sync = data.sync;
}
Expand Down
6 changes: 6 additions & 0 deletions engine/src/Options/Classes/ColorAnimation.ts
Expand Up @@ -12,13 +12,15 @@ export class ColorAnimation implements IColorAnimation, IOptionLoader<IColorAnim
enable;
offset: RangeValue;
speed: RangeValue;
decay: RangeValue;
sync;

constructor() {
this.count = 0;
this.enable = false;
this.offset = 0;
this.speed = 1;
this.decay = 0;
this.sync = true;
}

Expand All @@ -43,6 +45,10 @@ export class ColorAnimation implements IColorAnimation, IOptionLoader<IColorAnim
this.speed = setRangeValue(data.speed);
}

if (data.decay !== undefined) {
this.decay = setRangeValue(data.decay);
}

if (data.sync !== undefined) {
this.sync = data.sync;
}
Expand Down
40 changes: 40 additions & 0 deletions engine/src/Options/Classes/Gradients/AnimatableGradient.ts
@@ -0,0 +1,40 @@
import { AnimatableGradientColor } from "./AnimatableGradientColor";
import { GradientAngle } from "./GradientAngle";
import { GradientType } from "../../../Enums/Types/GradientType";
import type { IAnimatableGradient } from "../../Interfaces/IAnimatableGradient";
import type { IOptionLoader } from "../../Interfaces/IOptionLoader";
import type { RecursivePartial } from "../../../Types/RecursivePartial";

export class AnimatableGradient implements IAnimatableGradient, IOptionLoader<IAnimatableGradient> {
angle: GradientAngle;
colors: AnimatableGradientColor[];
type: GradientType;

constructor() {
this.angle = new GradientAngle();
this.colors = [];
this.type = GradientType.random;
}

load(data?: RecursivePartial<IAnimatableGradient>): void {
if (!data) {
return;
}

this.angle.load(data.angle);

if (data.colors !== undefined) {
this.colors = data.colors.map((s) => {
const tmp = new AnimatableGradientColor();

tmp.load(s);

return tmp;
});
}

if (data.type !== undefined) {
this.type = data.type;
}
}
}
38 changes: 38 additions & 0 deletions engine/src/Options/Classes/Gradients/AnimatableGradientColor.ts
@@ -0,0 +1,38 @@
import { AnimatableColor } from "../AnimatableColor";
import { GradientColorOpacity } from "./GradientColorOpacity";
import type { IAnimatableGradientColor } from "../../Interfaces/IOptionsGradient";
import type { IOptionLoader } from "../../Interfaces/IOptionLoader";
import type { RecursivePartial } from "../../../Types/RecursivePartial";

export class AnimatableGradientColor implements IAnimatableGradientColor, IOptionLoader<IAnimatableGradientColor> {
stop;
value;
opacity?: GradientColorOpacity;

constructor() {
this.stop = 0;
this.value = new AnimatableColor();
}

load(data?: RecursivePartial<IAnimatableGradientColor>): void {
if (!data) {
return;
}

if (data.stop !== undefined) {
this.stop = data.stop;
}

this.value = AnimatableColor.create(this.value, data.value);

if (data.opacity !== undefined) {
this.opacity = new GradientColorOpacity();

if (typeof data.opacity === "number") {
this.opacity.value = data.opacity;
} else {
this.opacity.load(data.opacity);
}
}
}
}

0 comments on commit 954858e

Please sign in to comment.