-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
148 lines (118 loc) · 3.31 KB
/
index.js
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
const canvas = document.querySelector("canvas");
const secondsCount = document.querySelector(".seconds");
const level = document.querySelector(".grade");
const context = canvas.getContext("2d");
const catDimensions = { width: 353 * 1.2, height: 325 * 1.2 };
const levels = {
5: "Pilgrim",
10: "Servant",
15: "lil mew mew",
35: "Ugly Eunuch",
65: "Laundry Hoarder",
105: "Lord of Leftovers",
150: "Rotten onion smeller",
250: "Instagram Doomscroller",
450: "Subreddit Stalker",
650: "Infinite Snack Muncher",
1000: "Virtual AFK Champion",
1500: "Darkmode Incarnate",
2500: "Panting Gooner",
3500: "Dark Mode Devotee",
4500: "Get a life bruh",
10500: "Dark Circle Warrior",
20500: "Supreme Time Waster",
};
const startTime = Date.now();
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
context.translate(window.innerWidth / 2, window.innerHeight / 2);
const image = new Image();
image.src = "caticon3.jpg";
const loopingCats = 40; //
const offsetDistance = 120;
let currentOffset = 0;
const movementRange = 200;
const mouseOffset = {
x: 0,
y: 0,
};
const movementOffset = {
x: 0,
y: 0,
};
image.onload = () => {
startLooping();
};
window.onresize = () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
context.setTransform(1, 0, 0, 1, 0, 0);
context.translate(window.innerWidth / 2, window.innerHeight / 2);
};
window.addEventListener("mousemove", onMouseMove);
function draw(offset, loopCount) {
let currentPercentage = (loopingCats - loopCount) / loopingCats;
context.drawImage(
image,
-catDimensions.width / 2 -
offset / 2 +
movementOffset.x * currentPercentage,
-catDimensions.height / 2 -
offset / 2 +
movementOffset.y * currentPercentage,
catDimensions.width + offset,
catDimensions.height + offset
);
}
function onMouseMove(e) {
mouseOffset.x =
((e.clientX - window.innerWidth / 2) / window.innerWidth / 2) *
movementRange;
mouseOffset.y =
((e.clientY - window.innerHeight / 2) / window.innerHeight / 2) *
movementRange;
}
function lerp(start, end, amount) {
return start * (1 - amount) + end * amount;
}
function loopDraw() {
movementOffset.x = lerp(movementOffset.x, mouseOffset.x, 0.05);
movementOffset.y = lerp(movementOffset.y, mouseOffset.y, 0.05);
for (let i = loopingCats; i >= 1; i--) {
draw(i * offsetDistance + currentOffset, i);
}
draw(offsetDistance, 1);
currentOffset++;
if (currentOffset >= offsetDistance) {
currentOffset = 0;
}
const newTime = Math.floor((Date.now() - startTime) / 1000);
secondsCount.innerText = newTime;
if (levels[newTime]) {
level.innerText = levels[newTime];
}
requestAnimationFrame(loopDraw);
}
function startLooping() {
requestAnimationFrame(loopDraw);
}
const catImages = [
"cat.png",
"caticon2.jpg", // Replace with your actual image paths
"caticon3.jpg",
"caticon4.jpg" ,
"caticon5.jpg" ,
"caticon6.jpg" ,
"caticon7.jpg" ,
"caticon8.jpg" ,
"caticon9.jpg" ,
"caticon10.jpg" ,
"caticon11.jpeg"
];
let currentImageIndex = 0;
document.addEventListener("click", changeCatImage);
function changeCatImage() {
// Cycle through the images array
currentImageIndex = (currentImageIndex + 1) % catImages.length;
image.src = catImages[currentImageIndex]; // Update the image source
}