-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathripple.js
More file actions
54 lines (49 loc) · 1.34 KB
/
ripple.js
File metadata and controls
54 lines (49 loc) · 1.34 KB
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
48
49
50
51
52
53
54
import { easeOutCirc, easeInCubic } from "./easings.js";
import { progress, transition } from "./helpers.js";
import { red } from "./colors.js";
export const makeRipple = (canvasManager, startPosition) => {
const CTX = canvasManager.getContext();
const rippleDuration = 800;
const rippleStart = Date.now();
let position = { ...startPosition };
let gone = false;
const draw = () => {
if (!gone) {
const timeSinceRipple = Date.now() - rippleStart;
if (timeSinceRipple > rippleDuration) gone = true;
const animationProgress = progress(0, rippleDuration, timeSinceRipple);
const opacityTransition = transition(
1,
0,
animationProgress,
easeInCubic
);
const scaleTransition = transition(
0,
2.5,
animationProgress,
easeOutCirc
);
const lineWidthTransition = transition(
8,
0,
animationProgress,
easeOutCirc
);
CTX.save();
CTX.strokeStyle = red;
CTX.globalAlpha = opacityTransition;
CTX.lineWidth = lineWidthTransition;
CTX.translate(position.x, position.y);
CTX.scale(scaleTransition, scaleTransition);
CTX.beginPath();
CTX.arc(0, 0, 22, 0, 2 * Math.PI);
CTX.closePath();
CTX.stroke();
CTX.restore();
}
};
return {
draw,
};
};