Skip to content

Commit

Permalink
fix: fixed path rotation with noise setting, path rotation now ignore…
Browse files Browse the repository at this point in the history
…s rotate animation
  • Loading branch information
matteobruni committed Jul 22, 2020
1 parent 8509f72 commit 554fef1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions core/main/src/Core/Interfaces/IParticle.ts
Expand Up @@ -16,6 +16,7 @@ export interface IParticle {
randomIndexData?: number;

readonly angle: number;
readonly pathAngle: number;
readonly bubble: IBubbleParticleData;
readonly color: IHsl | undefined;
readonly close: boolean;
Expand Down
8 changes: 4 additions & 4 deletions core/main/src/Core/Particle.ts
Expand Up @@ -41,6 +41,7 @@ import { Mover } from "./Particle/Mover";
*/
export class Particle implements IParticle {
public angle: number;
public pathAngle: number;
public destroyed: boolean;
public rotateDirection: RotateDirection | keyof typeof RotateDirection | RotateDirectionAlt;
public randomIndexData?: number;
Expand Down Expand Up @@ -187,12 +188,11 @@ export class Particle implements IParticle {
};

const rotateOptions = this.particlesOptions.rotate;
const initialAngle = rotateOptions.path
? Math.atan2(this.initialVelocity.vertical, this.initialVelocity.horizontal)
: 0;

const degAngle = rotateOptions.random ? Math.random() * 360 : rotateOptions.value;

this.angle = initialAngle + (degAngle * Math.PI) / 180;
this.angle = (degAngle * Math.PI) / 180;
this.pathAngle = Math.atan2(this.initialVelocity.vertical, this.initialVelocity.horizontal);

this.rotateDirection = rotateOptions.direction;

Expand Down
41 changes: 23 additions & 18 deletions core/main/src/Core/Particle/Updater.ts
Expand Up @@ -105,27 +105,32 @@ export class Updater {

private updateAngle(delta: IDelta): void {
const particle = this.particle;
const rotateAnimation = particle.particlesOptions.rotate.animation;
const rotate = particle.particlesOptions.rotate;
const rotateAnimation = rotate.animation;
const speed = (rotateAnimation.speed / 360) * delta.factor;
const max = 2 * Math.PI;

if (rotateAnimation.enable) {
switch (particle.rotateDirection) {
case RotateDirection.clockwise:
particle.angle += speed;

if (particle.angle > max) {
particle.angle -= max;
}
break;
case RotateDirection.counterClockwise:
default:
particle.angle -= speed;

if (particle.angle < 0) {
particle.angle += max;
}
break;
if (rotate.path) {
particle.pathAngle = Math.atan2(particle.velocity.vertical, particle.velocity.horizontal);
} else {
if (rotateAnimation.enable) {
switch (particle.rotateDirection) {
case RotateDirection.clockwise:
particle.angle += speed;

if (particle.angle > max) {
particle.angle -= max;
}
break;
case RotateDirection.counterClockwise:
default:
particle.angle -= speed;

if (particle.angle < 0) {
particle.angle += max;
}
break;
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion core/main/src/Utils/CanvasUtils.ts
Expand Up @@ -230,7 +230,11 @@ export class CanvasUtils {
context.beginPath();

if (particle.angle !== 0) {
context.rotate(particle.angle);
if (particle.particlesOptions.rotate.path) {
context.rotate(particle.angle + particle.pathAngle);
} else {
context.rotate(particle.angle);
}
}

if (backgroundMask) {
Expand Down

0 comments on commit 554fef1

Please sign in to comment.