-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
247 lines (205 loc) · 8.61 KB
/
Copy pathscript.js
File metadata and controls
247 lines (205 loc) · 8.61 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
var canvas = document.getElementById("starfield");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var context = canvas.getContext("2d");
var stars = 500;
var colorrange = [0, 60, 240];
var starArray = [];
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Initialize stars with random opacity values
for (var i = 0; i < stars; i++) {
var x = Math.random() * canvas.offsetWidth;
var y = Math.random() * canvas.offsetHeight;
var radius = Math.random() * 1.2;
var hue = colorrange[getRandom(0, colorrange.length - 1)];
var sat = getRandom(50, 100);
var opacity = Math.random();
starArray.push({ x, y, radius, hue, sat, opacity });
}
var frameNumber = 0;
var opacity = 0;
var secondOpacity = 0;
var thirdOpacity = 0;
var baseFrame = context.getImageData(0, 0, window.innerWidth, window.innerHeight);
function drawStars() {
for (var i = 0; i < stars; i++) {
var star = starArray[i];
context.beginPath();
context.arc(star.x, star.y, star.radius, 0, 360);
context.fillStyle = "hsla(" + star.hue + ", " + star.sat + "%, 88%, " + star.opacity + ")";
context.fill();
}
}
function updateStars() {
for (var i = 0; i < stars; i++) {
if (Math.random() > 0.99) {
starArray[i].opacity = Math.random();
}
}
}
const button = document.getElementById("valentinesButton");
button.addEventListener("click", () => {
if (button.textContent === "Click Me! ❤") {
button.textContent = "loading...";
fetch('send_mail.php')
.then(response => {
if (response.ok) {
button.textContent = "Check Your Email 🙃";
} else {
console.error('Failed to send email');
button.textContent = "Error 😞";
}
})
.catch(error => {
// Handle network errors or other issues
console.error('Error:', error);
button.textContent = "Error 😞";
});
}
});
function drawTextWithLineBreaks(lines, x, y, fontSize, lineHeight) {
lines.forEach((line, index) => {
context.fillText(line, x, y + index * (fontSize + lineHeight));
});
}
function drawText() {
var fontSize = Math.min(30, window.innerWidth / 24); // Adjust font size based on screen width
var lineHeight = 8;
context.font = fontSize + "px Comic Sans MS";
context.textAlign = "center";
// glow effect
context.shadowColor = "rgba(45, 45, 255, 1)";
context.shadowBlur = 8;
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
if(frameNumber < 250){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("everyday day I cannot believe how lucky I am", canvas.width/2, canvas.height/2);
opacity = opacity + 0.01;
}
//fades out the text by decreasing the opacity
if(frameNumber >= 250 && frameNumber < 500){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("everyday day I cannot believe how lucky I am", canvas.width/2, canvas.height/2);
opacity = opacity - 0.01;
}
//needs this if statement to reset the opacity before next statement on canvas
if(frameNumber == 500){
opacity = 0;
}
if(frameNumber > 500 && frameNumber < 750){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
if (window.innerWidth < 600) { //shortens long sentence for mobile screens
drawTextWithLineBreaks(["amongst trillions and trillions of stars,", "over billions of years"], canvas.width / 2, canvas.height / 2, fontSize, lineHeight);
} else {
context.fillText("amongst trillions and trillions of stars, over billions of years", canvas.width/2, canvas.height/2);
}
opacity = opacity + 0.01;
}
if(frameNumber >= 750 && frameNumber < 1000){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
if (window.innerWidth < 600) {
drawTextWithLineBreaks(["amongst trillions and trillions of stars,", "over billions of years"], canvas.width / 2, canvas.height / 2, fontSize, lineHeight);
} else {
context.fillText("amongst trillions and trillions of stars, over billions of years", canvas.width/2, canvas.height/2);
}
opacity = opacity - 0.01;
}
if(frameNumber == 1000){
opacity = 0;
}
if(frameNumber > 1000 && frameNumber < 1250){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("to be alive, and to get to spend this life with you", canvas.width/2, canvas.height/2);
opacity = opacity + 0.01;
}
if(frameNumber >= 1250 && frameNumber < 1500){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("to be alive, and to get to spend this life with you", canvas.width/2, canvas.height/2);
opacity = opacity - 0.01;
}
if(frameNumber == 1500){
opacity = 0;
}
if(frameNumber > 1500 && frameNumber < 1750){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("is so incredibly, unfathomably unlikely", canvas.width/2, canvas.height/2);
opacity = opacity + 0.01;
}
if(frameNumber >= 1750 && frameNumber < 2000){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
context.fillText("is so incredibly, unfathomably unlikely", canvas.width/2, canvas.height/2);
opacity = opacity - 0.01;
}
if(frameNumber == 2000){
opacity = 0;
}
if(frameNumber > 2000 && frameNumber < 2250){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
if (window.innerWidth < 600) {
drawTextWithLineBreaks(["and yet here I am to get the impossible", "chance to get to know you"], canvas.width / 2, canvas.height / 2, fontSize, lineHeight);
} else {
context.fillText("and yet here I am to get the impossible chance to get to know you", canvas.width/2, canvas.height/2);
}
opacity = opacity + 0.01;
}
if(frameNumber >= 2250 && frameNumber < 2500){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
if (window.innerWidth < 600) {
drawTextWithLineBreaks(["and yet here I am to get the impossible", "chance to get to know you"], canvas.width / 2, canvas.height / 2, fontSize, lineHeight);
} else {
context.fillText("and yet here I am to get the impossible chance to get to know you", canvas.width/2, canvas.height/2);
}
opacity = opacity - 0.01;
}
if(frameNumber == 2500){
opacity = 0;
}
if(frameNumber > 2500 && frameNumber < 99999){
context.fillStyle = `rgba(45, 45, 255, ${opacity})`;
if (window.innerWidth < 600) {
drawTextWithLineBreaks(["I love you so much {name}, more than", "all the time and space in the universe can contain"], canvas.width / 2, canvas.height / 2, fontSize, lineHeight);
} else {
context.fillText("I love you so much {name}, more than all the time and space in the universe can contain", canvas.width/2, canvas.height/2);
}
opacity = opacity + 0.01;
}
if(frameNumber >= 2750 && frameNumber < 99999){
context.fillStyle = `rgba(45, 45, 255, ${secondOpacity})`;
if (window.innerWidth < 600) {
drawTextWithLineBreaks(["and I can't wait to spend all the time in", "the world to share that love with you!"], canvas.width / 2, (canvas.height/2 + 60), fontSize, lineHeight);
} else {
context.fillText("and I can't wait to spend all the time in the world to share that love with you!", canvas.width/2, (canvas.height/2 + 50));
}
secondOpacity = secondOpacity + 0.01;
}
if(frameNumber >= 3000 && frameNumber < 99999){
context.fillStyle = `rgba(45, 45, 255, ${thirdOpacity})`;
context.fillText("Happy Valentine's Day <3", canvas.width/2, (canvas.height/2 + 120));
thirdOpacity = thirdOpacity + 0.01;
button.style.display = "block";
}
// Reset the shadow effect after drawing the text
context.shadowColor = "transparent";
context.shadowBlur = 0;
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
}
function draw() {
context.putImageData(baseFrame, 0, 0);
drawStars();
updateStars();
drawText();
if (frameNumber < 99999) {
frameNumber++;
}
window.requestAnimationFrame(draw);
}
window.addEventListener("resize", function () {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
baseFrame = context.getImageData(0, 0, window.innerWidth, window.innerHeight);
});
window.requestAnimationFrame(draw);