-
-
Notifications
You must be signed in to change notification settings - Fork 800
/
Utils.ts
47 lines (40 loc) · 1.27 KB
/
Utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { type IHsl, type Particle, degToRad, getStyleFromHsl } from "@tsparticles/engine";
const minWidth = 0,
half = 0.5,
double = 2;
/**
* Draws an ellipse for the given particle.
* @param context - The canvas context.
* @param particle - The particle to draw.
* @param fillColorValue - The particle fill color.
* @param radius - The radius of the particle.
* @param opacity - The opacity of the particle.
* @param width - The width of the particle.
* @param rotation - The rotation of the particle.
* @param start - The start angle of the particle.
* @param end - The end angle of the particle.
*/
export function drawEllipse(
context: CanvasRenderingContext2D,
particle: Particle,
fillColorValue: IHsl | undefined,
radius: number,
opacity: number,
width: number,
rotation: number,
start: number,
end: number,
): void {
if (width <= minWidth) {
return;
}
const pos = particle.getPosition();
if (fillColorValue) {
context.strokeStyle = getStyleFromHsl(fillColorValue, opacity);
}
context.lineWidth = width;
const rotationRadian = degToRad(rotation);
context.beginPath();
context.ellipse(pos.x, pos.y, radius * half, radius * double, rotationRadian, start, end);
context.stroke();
}