-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheffects.js
More file actions
169 lines (167 loc) · 6.99 KB
/
effects.js
File metadata and controls
169 lines (167 loc) · 6.99 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
export const effects = {
typewriter: {
name: 'Typewriter',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
ctx.globalAlpha = charProgress > 0 ? 1 : 0;
ctx.fillText(char, x, y);
}
},
fade: {
name: 'Fade In',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
ctx.globalAlpha = charProgress;
ctx.fillText(char, x, y);
}
},
slideUp: {
name: 'Slide Up',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const ease = 1 - Math.pow(1 - charProgress, 3);
ctx.globalAlpha = charProgress;
ctx.fillText(char, x, y + (1 - ease) * (fontSize * 0.8));
}
},
popIn: {
name: 'Pop In',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const c1 = 1.70158;
const c3 = c1 + 1;
const ease = charProgress === 1 ? 1 : 1 + c3 * Math.pow(charProgress - 1, 3) + c1 * Math.pow(charProgress - 1, 2);
ctx.globalAlpha = charProgress;
ctx.translate(x, y);
ctx.scale(Math.max(0, ease), Math.max(0, ease));
ctx.fillText(char, 0, 0);
}
},
blur: {
name: 'Blur Reveal',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const blurAmount = (1 - charProgress) * (fontSize * 0.2);
ctx.filter = `blur(${blurAmount}px)`;
ctx.globalAlpha = charProgress;
ctx.fillText(char, x, y);
}
},
glitch: {
name: 'Cyber Glitch',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex, textColor) => {
if (charProgress < 1) {
const noise = Math.random();
const shiftX = (Math.random() - 0.5) * fontSize * 0.3;
const shiftY = (Math.random() - 0.5) * fontSize * 0.1;
if (noise > 0.7) {
ctx.fillStyle = '#ff003c';
ctx.fillText(char, x + shiftX + 4, y + shiftY);
ctx.fillStyle = '#00f0ff';
ctx.fillText(char, x + shiftX - 4, y + shiftY);
}
ctx.fillStyle = textColor;
ctx.globalAlpha = Math.random() * 0.5 + 0.5;
ctx.fillText(char, x + shiftX, y + shiftY);
} else {
ctx.fillText(char, x, y);
}
}
},
elasticDrop: {
name: 'Elastic Drop',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const p = charProgress;
const c4 = (2 * Math.PI) / 3;
const ease = p === 0 ? 0 : p === 1 ? 1 : Math.pow(2, -10 * p) * Math.sin((p * 10 - 0.75) * c4) + 1;
ctx.globalAlpha = Math.min(1, p * 3);
ctx.fillText(char, x, y - (height / 2) * (1 - ease));
}
},
trackingIn: {
name: 'Cinematic Tracking',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const ease = 1 - Math.pow(1 - charProgress, 4);
const centerX = width / 2;
const distFromCenter = x - centerX;
const currentX = centerX + distFromCenter * (1 + (1 - ease) * 3);
ctx.globalAlpha = charProgress;
ctx.filter = `blur(${(1-ease)*8}px)`;
ctx.fillText(char, currentX, y);
}
},
focusBlur: {
name: 'Focus Pull',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const ease = 1 - Math.pow(1 - charProgress, 3);
const blur = (1 - ease) * 20;
ctx.globalAlpha = charProgress;
ctx.filter = `blur(${blur}px)`;
ctx.translate(x, y);
ctx.scale(1 + (1-ease)*2, 1 + (1-ease)*2);
ctx.fillText(char, 0, 0);
}
},
wave: {
name: 'Sine Wave',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex, textColor, progress) => {
const ease = 1 - Math.pow(1 - charProgress, 3);
ctx.globalAlpha = charProgress;
const waveY = Math.sin(charIndex * 0.5 + progress * Math.PI * 10) * (fontSize * 0.5) * (1 - ease);
ctx.fillText(char, x, y + waveY);
}
},
shatterIn: {
name: 'Shatter In',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const ease = 1 - Math.pow(1 - charProgress, 3);
const randX = Math.abs(Math.sin(charIndex * 12.9898) * 43758.5453) % 1;
const randY = Math.abs(Math.cos(charIndex * 78.233) * 43758.5453) % 1;
const randRot = Math.abs(Math.sin(charIndex * 45.123) * 43758.5453) % 1;
const startOffsetX = (randX - 0.5) * width;
const startOffsetY = (randY - 0.5) * height;
const startRot = (randRot - 0.5) * Math.PI * 4;
ctx.globalAlpha = charProgress;
ctx.translate(x + startOffsetX * (1 - ease), y + startOffsetY * (1 - ease));
ctx.rotate(startRot * (1 - ease));
ctx.fillText(char, 0, 0);
}
},
neonFlicker: {
name: 'Neon Flicker',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex, textColor) => {
if (charProgress < 1) {
const flicker = Math.random() > 0.5 ? 1 : 0.2;
ctx.globalAlpha = flicker * charProgress;
ctx.shadowColor = textColor;
ctx.shadowBlur = flicker === 1 ? 20 : 0;
} else {
ctx.globalAlpha = 1;
ctx.shadowColor = textColor;
ctx.shadowBlur = 10;
}
ctx.fillText(char, x, y);
}
},
stretchSnap: {
name: 'Stretch & Snap',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex) => {
const ease = 1 - Math.pow(1 - charProgress, 4);
ctx.globalAlpha = charProgress;
ctx.translate(x, y);
const scaleY = 1 + (1 - ease) * 4;
const scaleX = 1 - (1 - ease) * 0.5;
ctx.scale(scaleX, scaleY);
ctx.fillText(char, 0, 0);
}
},
increaseTracking: {
name: 'Increase Tracking',
render: (ctx, char, x, y, charProgress, fontSize, width, height, charIndex, textColor, progress, charInLine, lineLength) => {
const fadePhase = Math.min(1, charProgress / 0.9);
const trackingPhase = Math.max(0, Math.min(1, progress));
const easeTracking = 1 - Math.pow(1 - trackingPhase, 3);
const centerIndex = (lineLength - 1) / 2;
const distFromCenter = charInLine - centerIndex;
const maxTrackingPerStep = fontSize * 0.14;
const xOffset = distFromCenter * maxTrackingPerStep * easeTracking;
ctx.globalAlpha = fadePhase;
ctx.fillText(char, x + xOffset, y);
}
}
};