-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
217 lines (176 loc) · 5.97 KB
/
Copy pathindex.html
File metadata and controls
217 lines (176 loc) · 5.97 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
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<canvas id="paper" style="display: block;"></canvas>
<img src="icons/mute-2-xxl.png" alt="" data-play="false">
<style>
body {
margin: 0px;
padding: 0px;
}
#paper{
background: #1b1b1b;
width: 100%;
height: 100vh;
padding: 50px;
aspect-ratio: 1/1;
}
img{
z-index: 100;
position: absolute;
width: 75px;
height: 75px;
cursor: pointer;
}
</style>
<script>
const paper = document.querySelector("#paper"),
pen = paper.getContext("2d");
paper.style.display = "block";
let startTime = new Date().getTime();
const colors = [
"#fa206f",
"#ca4d96",
"#ab6aae",
"#8b88c7",
"#7a98d4",
"#6ea3de",
"#48c7fc",
"#5feffd",
"#3af5d0",
"#2cf8be",
"#16fba2",
"#01ff89"
];
// Эта штука определяет движется ли маятник по возрастанию или по убыванию
// нужно будет чтобы определить когда маятник касается пола
const settings = [];
for (let i = 0; i < colors.length; i++) {
let obj = {
ascending: true,
lastPosition: Math.PI
};
settings.push(obj);
}
const isBallDirectionChanged= function(index,currentBallPosition){
if(settings[index].ascending){
if(currentBallPosition>settings[index].lastPosition){
settings[index].lastPosition = currentBallPosition;
return false;
} else {
settings[index].lastPosition = currentBallPosition;
settings[index].ascending = false;
return true;
}
} else {
if(currentBallPosition<settings[index].lastPosition){
settings[index].lastPosition = currentBallPosition;
return false;
} else {
settings[index].lastPosition = currentBallPosition;
settings[index].ascending = true
return true;
}
}
}
const img = document.querySelector("img");
img.style.top = `15px`;
img.style.right = `${paper.clientWidth/2-150}px`;
img.addEventListener("click",()=>{
if(img.dataset.play==="true"){
img.dataset.play="false";
img.src = "icons/mute-2-xxl.png";
} else {
img.src = "icons/volume-up-4-xxl.png";
img.dataset.play="true";
}
})
const music = colors.map( (color, index) => {
const audio = new Audio(`music/BeepBox-${index+1} (mp3cut.net).wav`);
audio.volume = 0.15;
return audio;
});
const playMusic = index => music[index].play();
const draw = () => {
const time = 350; // Через это количество секунд маятники сойдутся воедино
paper.width = paper.clientWidth;
paper.height = paper.clientHeight;
const start = {
x: paper.width * 0.1,
y: paper.height * 0.85
};
const end = {
x: paper.width * 0.9,
y: paper.height * 0.85
};
const center = {
x: paper.width* 0.5,
y: paper.height * 0.85
}
pen.strokeStyle = "white";
pen.lineWidth = 6;
pen.beginPath();
pen.moveTo(start.x,start.y);
pen.lineTo(end.x,end.y);
pen.stroke();
const currentTime = new Date().getTime(), // Текущее время
elapsedTime = (currentTime - startTime)/1000; // Пройденное время
const lineLength = end.x - start.x ;
const firstArcRadius = (lineLength)* 0.1,
spacing = (lineLength/2 - firstArcRadius) / colors.length;//Длина полоски
pen.beginPath();
pen.arc(center.x,center.y,lineLength/2,Math.PI, 2*Math.PI);
pen.stroke();
// Цикл для отрисовки радиусов
colors.forEach((color, index)=>{
const numberOfLoops = 42 - index,
rasstoynie = Math.PI * numberOfLoops;
const velocity = rasstoynie/time; //Скорость движения маятников
const radius = firstArcRadius + (index*spacing), // радиус круга
distance = Math.PI + (elapsedTime*velocity) , // угол, здесь сейчас находится круг
modDistance = distance % 2* Math.PI, // Магия
CorrectedDistance = modDistance >= Math.PI ? modDistance : 2*Math.PI - modDistance,
x = center.x + radius * Math.cos(CorrectedDistance), //Позиция маятника по Х
y = center.y+ radius * Math.sin(CorrectedDistance);
pen.lineWidth = 4;
pen.beginPath();
pen.strokeStyle = color;
pen.fillStyle = color;
pen.moveTo(x, y);
pen.lineTo(center.x, center.y);
pen.strokeStyle = color;
pen.stroke();
});
// Цикл для отрисовки маятников
colors.forEach((color, index)=>{
const numberOfLoops = 42 - index,
rasstoynie = Math.PI * numberOfLoops;
const velocity = rasstoynie/time; //Скорость движения маятников
const radius = firstArcRadius + (index*spacing), // радиус круга
distance = Math.PI + (elapsedTime*velocity) , // угол, здесь сейчас находится круг
modDistance = distance % 2* Math.PI, // Магия
CorrectedDistance = modDistance >= Math.PI ? modDistance : 2*Math.PI - modDistance,
x = center.x + radius * Math.cos(CorrectedDistance), //Позиция маятника по Х
y = center.y+ radius * Math.sin(CorrectedDistance);
pen.beginPath();
pen.lineWidth = 2;
pen.strokeStyle = "white";
pen.fillStyle = "black";
pen.arc(x,y,(lineLength)*0.0095,0,2* Math.PI);
pen.fill();
pen.stroke();
if (isBallDirectionChanged(index,CorrectedDistance)&&(img.dataset.play==="true")){
playMusic(index);
}
});
requestAnimationFrame(draw); // Запрашивает браузер обновлять draw() с частотой монитра
// distance% 2*Math.PI === Math.PI || distance% 2*Math.PI === 0
};
draw();
</script>
</body>
</html>