Skip to content

Commit

Permalink
fix: added pixel ratio to shape drawers and fixed particle stroke width
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Jul 15, 2020
1 parent e977016 commit 2245dd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/main/src/Core/Interfaces/IParticle.ts
Expand Up @@ -35,6 +35,7 @@ export interface IParticle {
readonly shapeData?: IShapeValues;
readonly size: IParticleSizeAnimation;
readonly stroke: IStroke;
readonly strokeWidth: number;
readonly strokeColor: IHsl | undefined;
readonly velocity: IVelocity;
readonly linksDistance?: number;
Expand Down
3 changes: 3 additions & 0 deletions core/main/src/Core/Particle.ts
Expand Up @@ -53,6 +53,7 @@ export class Particle implements IParticle {
public readonly position: ICoordinates;
public readonly offset: ICoordinates;
public readonly color: IHsl | undefined;
public readonly strokeWidth: number;
public readonly strokeColor: IHsl | undefined;
public readonly shadowColor: IRgb | undefined;
public readonly opacity: IParticleOpacityAnimation;
Expand Down Expand Up @@ -300,6 +301,8 @@ export class Particle implements IParticle {
? Utils.itemFromArray(this.particlesOptions.stroke)
: this.particlesOptions.stroke;

this.strokeWidth = this.stroke.width * container.retina.pixelRatio;

/* strokeColor */
this.strokeColor = ColorUtils.colorToHsl(this.stroke.color);

Expand Down
6 changes: 4 additions & 2 deletions core/main/src/Types/ShapeDrawerFunctions.ts
Expand Up @@ -6,7 +6,8 @@ export type ShapeDrawerDrawFunction = (
particle: IParticle,
radius: number,
opacity: number,
delta: number
delta: number,
pixelRatio: number
) => void;

export type ShapeDrawerInitFunction = (container: Container) => Promise<void>;
Expand All @@ -16,7 +17,8 @@ export type ShapeDrawerAfterEffectFunction = (
particle: IParticle,
radius: number,
opacity: number,
delta: number
delta: number,
pixelRatio: number
) => void;

export type ShapeDrawerDestroyFunction = (container: Container) => void;
6 changes: 3 additions & 3 deletions core/main/src/Utils/CanvasUtils.ts
Expand Up @@ -250,7 +250,7 @@ export class CanvasUtils {

const stroke = particle.stroke;

context.lineWidth = stroke.width;
context.lineWidth = particle.strokeWidth;
context.strokeStyle = strokeColorValue;

if (particle.close) {
Expand Down Expand Up @@ -302,7 +302,7 @@ export class CanvasUtils {
return;
}

drawer.draw(context, particle, radius, opacity, delta.value);
drawer.draw(context, particle, radius, opacity, delta.value, container.retina.pixelRatio);
}

public static drawShapeAfterEffect(
Expand All @@ -323,7 +323,7 @@ export class CanvasUtils {
return;
}

drawer.afterEffect(context, particle, radius, opacity, delta.value);
drawer.afterEffect(context, particle, radius, opacity, delta.value, container.retina.pixelRatio);
}

public static drawPlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, delta: IDelta): void {
Expand Down

0 comments on commit 2245dd0

Please sign in to comment.