-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
212 lines (173 loc) · 5.41 KB
/
index.html
File metadata and controls
212 lines (173 loc) · 5.41 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blue or red?</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Foldit:wght@500">
<style>
body {
background-color: #222;
overflow: hidden;
position: relative;
}
h1 {
color: #fff;
font-size: 2em;
text-align: center;
}
.buttons {
display: flex;
justify-content: center;
align-items: center;
margin-left: 30px;
margin-right: 30px;
}
.button {
width: 200px;
height: 100px;
margin: 20px;
border-radius: 15px;
}
.button.blue {
background-color: blue;
}
.button.red {
background-color: red;
}
.button span {
color: #fff;
font-size: 1.5em;
}
.counter {
margin-top: 10px;
}
.counter p {
color: #fff;
}
.letters {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
/* Aggiunto stile per colorare le lettere di verde e farle espandere */
.letter {
color: #0f0;
/* Colore verde intenso */
font-size: 50px;
/* Dimensione del font */
position: absolute;
animation: rain 0.50s linear;
/* Aggiungi un'animazione per il movimento delle lettere */
opacity: 2;
/* Opacità per un effetto leggermente sfocato */
white-space: nowrap;
/* Evita il ritorno a capo automatico */
}
@keyframes rain {
to {
transform: translateY(100%);
}
}
</style>
</head>
<body>
<h1>Blue or red?</h1>
<div class="buttons">
<button type="button" class="button blue" id="button-blue">
<span>Blue</span>
</button>
<button type="button" class="button red" id="button-red">
<span>Red</span>
</button>
</div>
<div class="counter">
<p>Blue: <span id="counter-blue">0</span></p>
<p>Red: <span id="counter-red">0</span></p>
</div>
<div class="letters"></div>
<script>
window.onload = function () {
const buttonRed = document.getElementById("button-red");
const buttonBlue = document.getElementById("button-blue");
const counterBlue = document.getElementById("counter-blue");
const counterRed = document.getElementById("counter-red");
const lettersDiv = document.querySelector(".letters");
let isAnimationStarted = false;
buttonRed.addEventListener("click", handleRed);
buttonBlue.addEventListener("click", handleBlue);
// Imposta un limite massimo di lettere
const maxLetters = 1000;
let letterCount = 0;
function createRandomLetter() {
const alphabet = "abcdefghijklmnopqrstuvwxyz가나다라마바사아자차카타파하абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
const randomIndex = Math.floor(Math.random() * alphabet.length);
return alphabet[randomIndex];
}
function checkOverlap(letterElement, existingLetters) {
const letterRect = letterElement.getBoundingClientRect();
for (const existingLetter of existingLetters) {
const existingRect = existingLetter.getBoundingClientRect();
if (
letterRect.left < existingRect.right &&
letterRect.right > existingRect.left &&
letterRect.top < existingRect.bottom &&
letterRect.bottom > existingRect.top
) {
// Sovrapposizione rilevata, sposta la lettera
const randomX = Math.random() * 270;
const randomY = Math.random() * 270;
letterElement.style.left = `${randomX}%`;
letterElement.style.top = `${randomY}%`;
return checkOverlap(letterElement, existingLetters);
}
}
}
function addLetter() {
if (isScreenFull()) {
return;
}
const letter = createRandomLetter();
const letterElement = document.createElement("div");
letterElement.classList.add("letter");
letterElement.textContent = letter;
const randomX = Math.random() * 90;
const randomY = Math.random() * 700;
letterElement.style.left = `${randomX}%`;
letterElement.style.top = `${randomY}%`;
checkOverlap(letterElement, lettersDiv.querySelectorAll('.letter'));
lettersDiv.appendChild(letterElement);
letterCount++; // Incrementa il conteggio delle lettere
}
function startAnimation() {
isAnimationStarted = true;
addLetter();
setInterval(addLetter, 0.20); // Cambia da 100 a 20 millisecondi per rendere l'animazione più veloce
}
function isScreenFull() {
return letterCount >= 3000;
}
function makeSiteGreen() {
document.body.style.backgroundColor = "green";
}
function handleRed() {
if (!isAnimationStarted) {
startAnimation();
}
counterRed.textContent = parseInt(counterRed.textContent) + 1;
buttonRed.setAttribute("disabled", "disabled");
buttonBlue.setAttribute("disabled", "disabled");
}
function handleBlue() {
if (!isAnimationStarted) {
startAnimation();
}
counterBlue.textContent = parseInt(counterBlue.textContent) + 1;
buttonRed.setAttribute("disabled", "disabled");
buttonBlue.setAttribute("disabled", "disabled");
}
}
</script>
</body>
</html>