Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·104 lines (86 loc) · 2.77 KB
/
Copy pathscript.js
File metadata and controls
executable file
·104 lines (86 loc) · 2.77 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
const canvas = document.getElementById("fallingLeavesCanvas");
const ctx = canvas.getContext("2d");
const leaves = [];
const numLeaves = 200;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
function createLeaf() {
return {
x: Math.random() * canvas.width,
y: Math.random() * 18 + 2,
size: Math.random() * 22 + 3, // Random size between 3 and 25
speed: Math.random() * 3 + 1, // Random speed between 1 and 4
color: `rgba(${Math.random() * 200 + 50}, ${Math.random() * 200 + 50}, ${Math.random() * 200 + 50}, ${Math.random() * 0.8 + 0.2})`, // Random color
//color: `rgba(255, ${Math.random() * 100 + 100}, 0, ${Math.random() * 0.8 + 0.2})`, // Random orange-ish color
//color: '#000A',
rotation: Math.random() * 360 // Random initial rotation
};
}
function createLeaves() {
for (let i = 0; i < numLeaves; i++) {
leaves.push(createLeaf());
}
}
function updateLeaves() {
for (let i = 0; i < leaves.length; i++) {
const leaf = leaves[i];
leaf.y += leaf.speed;
leaf.x += 1.0 * Math.sin(leaf.y / leaf.size);
if (leaf.y > canvas.height) {
// Reset the leaf when it goes below the canvas
leaf.y = -20;
leaf.x = Math.random() * canvas.width;
}
}
}
function drawLeaves() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < leaves.length; i++) {
const leaf = leaves[i];
ctx.save();
ctx.translate(leaf.x + leaf.size / 2, leaf.y + leaf.size / 2);
ctx.rotate((leaf.rotation * Math.PI) / 180);
ctx.fillStyle = leaf.color;
ctx.fillRect(-leaf.size / 2, -leaf.size / 2, leaf.size, leaf.size);
//ctx.beginPath();
//ctx.arc(200,150,leaf.size,0,0.5*Math.PI);
//ctx.arc(200+leaf.size,150+leaf.size,leaf.size,Math.PI, 1.5*Math.PI);
//ctx.fillStyle = leaf.color;
//ctx.fill();
//ctx.closePath();
ctx.restore();
}
}
function animate() {
updateLeaves();
drawLeaves();
requestAnimationFrame(animate);
}
function onWindowResize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener("resize", onWindowResize);
createLeaves();
animate();
function changeTextColor() {
const textContainer = document.getElementById("text-container");
const words = textContainer.innerText.split(" ");
const coloredWords = words.map((word) => {
const randomColor = getRandomColor();
return `<span style="color: ${randomColor};">${word}</span>`;
});
textContainer.innerHTML = coloredWords.join(" ");
}
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
//function getRandomColor() {
// return Math.random() * 0xffffff;
//}
setInterval(changeTextColor, 1000);