@@ -7,6 +7,11 @@ export enum ParticleShape {
7
7
Strip ,
8
8
}
9
9
10
+ enum RotationDirection {
11
+ Positive ,
12
+ Negative ,
13
+ }
14
+
10
15
export default class Particle {
11
16
constructor ( context : CanvasRenderingContext2D , getOptions : ( ) => IConfettiOptions , x : number , y : number ) {
12
17
this . getOptions = getOptions
@@ -24,7 +29,7 @@ export default class Particle {
24
29
this . angularSpin = randomRange ( - 0.2 , 0.2 )
25
30
this . color = colors [ Math . floor ( Math . random ( ) * colors . length ) ]
26
31
this . rotateY = randomRange ( 0 , 1 )
27
- this . rotateDirection = 1
32
+ this . rotationDirection = RotationDirection . Positive
28
33
}
29
34
context : CanvasRenderingContext2D
30
35
radius : number
@@ -39,6 +44,7 @@ export default class Particle {
39
44
angularSpin : number
40
45
color : string
41
46
rotateY : number
47
+ rotationDirection : RotationDirection
42
48
getOptions : ( ) => IConfettiOptions
43
49
44
50
update ( ) {
@@ -55,13 +61,13 @@ export default class Particle {
55
61
this . vx += wind
56
62
this . vx *= friction
57
63
this . vy *= friction
58
- if ( this . rotateY >= 1 && this . rotateDirection === 1 ) {
59
- this . rotateDirection = - 1
60
- } else if ( this . rotateY <= - 1 && this . rotateDirection === - 1 ) {
61
- this . rotateDirection = 1
64
+ if ( this . rotateY >= 1 && this . rotationDirection === RotationDirection . Positive ) {
65
+ this . rotationDirection = RotationDirection . Negative
66
+ } else if ( this . rotateY <= - 1 && this . rotationDirection === RotationDirection . Negative ) {
67
+ this . rotationDirection = RotationDirection . Positive
62
68
}
63
69
64
- const rotateDelta = 0.1 * this . rotateDirection
70
+ const rotateDelta = 0.1 * this . rotationDirection
65
71
66
72
this . rotateY += rotateDelta
67
73
this . angle += this . angularSpin
0 commit comments