-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
867 lines (768 loc) · 32.3 KB
/
script.js
File metadata and controls
867 lines (768 loc) · 32.3 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
// script.js
console.log("🚀 Zed Red Games - Initializing...");
// Глобальная система логирования
window.ZedRedLogger = {
log: (message, type = 'info') => {
const timestamp = new Date().toLocaleTimeString();
const emoji = {
'info': 'ℹ️',
'success': '✅',
'warning': '⚠️',
'error': '❌',
'action': '🎯',
'theme': '🎨',
'animation': '✨',
'interaction': '👆'
}[type] || '📝';
console.log(`${emoji} [${timestamp}] ${message}`);
}
};
document.addEventListener("DOMContentLoaded", function () {
window.ZedRedLogger.log("DOM Content Loaded", 'success');
// Блокировка выделения текста и контекстного меню
document.addEventListener('contextmenu', (e) => {
window.ZedRedLogger.log("Context menu blocked", 'action');
e.preventDefault();
});
document.addEventListener('selectstart', (e) => {
window.ZedRedLogger.log("Text selection blocked", 'action');
e.preventDefault();
});
document.addEventListener('dragstart', (e) => {
window.ZedRedLogger.log("Drag start blocked", 'action');
e.preventDefault();
});
// Прелоадер - скрываем после загрузки всех ресурсов
function hidePreloader() {
window.ZedRedLogger.log("Hiding preloader", 'animation');
const preloader = document.getElementById('preloader');
if (preloader) {
preloader.classList.add('hidden');
setTimeout(() => {
preloader.style.display = 'none';
window.ZedRedLogger.log("Preloader hidden", 'success');
}, 500);
}
}
// Ждём загрузки всех изображений и ресурсов
function waitForResources() {
const images = document.querySelectorAll('img');
const iframes = document.querySelectorAll('iframe');
let loadedCount = 0;
const totalResources = images.length + iframes.length;
if (totalResources === 0) {
// Если нет ресурсов для загрузки, ждём минимум 1.5 секунды
setTimeout(hidePreloader, 1500);
return;
}
function checkComplete() {
loadedCount++;
if (loadedCount >= totalResources) {
// Минимальное время показа прелоадера
setTimeout(hidePreloader, 1000);
}
}
images.forEach(img => {
if (img.complete) {
checkComplete();
} else {
img.addEventListener('load', checkComplete);
img.addEventListener('error', checkComplete);
}
});
iframes.forEach(iframe => {
iframe.addEventListener('load', checkComplete);
iframe.addEventListener('error', checkComplete);
});
// Таймаут на случай, если что-то не загрузится
setTimeout(() => {
hidePreloader();
}, 5000);
}
// Запускаем проверку загрузки
waitForResources();
// Перетаскивание планет (blob) с инерцией
(function dragBlobs(){
const blobs = document.querySelectorAll('.blob');
let isDragging = false;
let dragBlob = null;
let startX, startY, initialX, initialY;
let velocityX = 0, velocityY = 0;
let lastMouseX, lastMouseY;
let animationId;
blobs.forEach(blob => {
blob.addEventListener('mousedown', (e) => {
window.ZedRedLogger.log("Planet drag started", 'interaction');
isDragging = true;
dragBlob = blob;
startX = e.clientX;
startY = e.clientY;
lastMouseX = e.clientX;
lastMouseY = e.clientY;
const rect = blob.getBoundingClientRect();
initialX = rect.left;
initialY = rect.top;
blob.style.animationPlayState = 'paused';
e.preventDefault();
});
});
document.addEventListener('mousemove', (e) => {
if (!isDragging || !dragBlob) return;
const deltaX = e.clientX - startX;
const deltaY = e.clientY - startY;
// Вычисляем скорость движения
velocityX = e.clientX - lastMouseX;
velocityY = e.clientY - lastMouseY;
lastMouseX = e.clientX;
lastMouseY = e.clientY;
dragBlob.style.transform = `translate(${initialX + deltaX}px, ${initialY + deltaY}px) scale(1.1)`;
});
document.addEventListener('mouseup', () => {
if (isDragging && dragBlob) {
window.ZedRedLogger.log("Planet drag ended", 'interaction');
isDragging = false;
// Запускаем движение по инерции
const currentRect = dragBlob.getBoundingClientRect();
let currentX = currentRect.left;
let currentY = currentRect.top;
function animateInertia() {
// Применяем скорость с затуханием
velocityX *= 0.95;
velocityY *= 0.95;
currentX += velocityX;
currentY += velocityY;
dragBlob.style.transform = `translate(${currentX}px, ${currentY}px) scale(1.1)`;
// Продолжаем анимацию пока есть скорость
if (Math.abs(velocityX) > 0.1 || Math.abs(velocityY) > 0.1) {
animationId = requestAnimationFrame(animateInertia);
} else {
// Возвращаем к обычной анимации
dragBlob.style.animationPlayState = 'running';
dragBlob.style.transform = '';
}
}
if (animationId) cancelAnimationFrame(animationId);
animateInertia();
dragBlob = null;
}
});
})();
// Плавная прокрутка
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
window.ZedRedLogger.log(`Navigation to: ${this.getAttribute("href")}`, 'action');
const header = document.querySelector('header');
const headerHeight = header ? header.getBoundingClientRect().height : 80;
const top = window.pageYOffset + target.getBoundingClientRect().top - (headerHeight + 10);
window.scrollTo({ top, behavior: "smooth" });
}
});
});
// Анимация при скролле
const animateOnScroll = () => {
document.querySelectorAll(".post, .banner").forEach((el) => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight * 0.75) {
if (el.style.opacity !== "1") {
window.ZedRedLogger.log(`Element animated: ${el.className}`, 'animation');
}
el.style.opacity = "1";
el.style.transform = "translateY(0)";
}
});
};
// Инициализация анимаций
document.querySelectorAll(".post, .banner").forEach((el) => {
el.style.opacity = "0";
el.style.transform = "translateY(20px)";
el.style.transition = "all 0.8s cubic-bezier(0.16, 1, 0.3, 1)";
});
window.addEventListener("scroll", animateOnScroll);
animateOnScroll();
// Параллакс эффект
window.addEventListener("scroll", function () {
document.body.style.backgroundPositionY = `${window.pageYOffset * 0.5}px`;
});
// Яркие иконки навигации с анимацией
document.querySelectorAll("nav a").forEach((link) => {
const img = link.querySelector("img");
link.addEventListener("mouseenter", () => {
window.ZedRedLogger.log(`Nav icon hover: ${link.textContent.trim()}`, 'interaction');
link.style.background = "rgba(255, 255, 255, 0.1)";
link.style.transform = "translateY(-3px)";
img.style.transform = "scale(1.2) rotate(5deg)";
img.style.filter =
"brightness(0) invert(1) drop-shadow(0 0 12px rgba(255, 255, 255, 0.9))";
});
link.addEventListener("mouseleave", () => {
window.ZedRedLogger.log(`Nav icon leave: ${link.textContent.trim()}`, 'interaction');
link.style.background = "";
link.style.transform = "";
img.style.transform = "";
img.style.filter =
"brightness(0) invert(1) drop-shadow(0 0 0px rgba(255, 255, 255, 0.7))";
});
});
// Плавные анимации для соцсетей
function initSocialIcons() {
document.querySelectorAll(".social-links a").forEach((link) => {
const img = link.querySelector("img");
// Удаляем старые обработчики если есть
link.removeEventListener("mouseenter", link._mouseenterHandler);
link.removeEventListener("mouseleave", link._mouseleaveHandler);
// Создаем новые обработчики
link._mouseenterHandler = () => {
window.ZedRedLogger.log(`Social icon hover: ${img.alt}`, 'interaction');
link.style.transform = "scale(1.3) translateY(-5px)";
img.style.filter = "brightness(1.2) saturate(1.5)";
};
link._mouseleaveHandler = () => {
window.ZedRedLogger.log(`Social icon leave: ${img.alt}`, 'interaction');
link.style.transform = "";
img.style.filter = "";
};
link.addEventListener("mouseenter", link._mouseenterHandler);
link.addEventListener("mouseleave", link._mouseleaveHandler);
});
}
// Инициализируем иконки социальных сетей
initSocialIcons();
// Анимация карточек
document.querySelectorAll(".banner, .post").forEach((card) => {
card.addEventListener("mouseenter", () => {
const isBanner = card.classList.contains("banner");
window.ZedRedLogger.log(`${isBanner ? 'Banner' : 'Card'} hover started`, 'interaction');
card.style.transform = `scale(${isBanner ? 1.02 : 1.03})`;
card.style.boxShadow = "0 15px 35px rgba(0, 0, 0, 0.4)";
});
card.addEventListener("mouseleave", () => {
const isBanner = card.classList.contains("banner");
window.ZedRedLogger.log(`${isBanner ? 'Banner' : 'Card'} hover ended`, 'interaction');
card.style.transform = "none";
card.style.boxShadow = "";
});
});
document.querySelectorAll(".post img").forEach((img) => {
img.addEventListener("mouseenter", () => {
window.ZedRedLogger.log(`Image hover: ${img.alt || 'Untitled'}`, 'interaction');
img.style.transform = "scale(1.05)";
img.style.boxShadow = "0 20px 40px rgba(0, 0, 0, 0.5)";
});
img.addEventListener("mouseleave", () => {
window.ZedRedLogger.log(`Image leave: ${img.alt || 'Untitled'}`, 'interaction');
img.style.transform = "scale(1)";
img.style.boxShadow = "0 10px 30px rgba(0, 0, 0, 0.3)";
});
});
// Анимация логотипа
document.querySelectorAll(".logo-link").forEach((link) => {
link.addEventListener("mouseenter", () => {
window.ZedRedLogger.log("Logo hover started", 'interaction');
link.style.transform = "scale(1.05)";
link.style.transition = "transform 0.5s ease";
});
link.addEventListener("mouseleave", () => {
window.ZedRedLogger.log("Logo hover ended", 'interaction');
link.style.transform = "";
link.style.background = "";
});
});
// Адаптивность
function handleResponsive() {
const header = document.querySelector("header");
const nav = document.querySelector("nav");
const bannerTitle = document.querySelector(".banner h1");
if (window.innerWidth <= 768) {
if (!header.style.flexDirection || header.style.flexDirection !== "column") {
window.ZedRedLogger.log("Responsive: Mobile layout activated", 'info');
}
header.style.flexDirection = "column";
header.style.padding = "15px";
nav.style.marginTop = "15px";
nav.style.flexWrap = "wrap";
nav.style.justifyContent = "center";
if (bannerTitle) bannerTitle.style.fontSize = "48px";
} else {
if (header.style.flexDirection === "column") {
window.ZedRedLogger.log("Responsive: Desktop layout activated", 'info');
}
header.style.flexDirection = "";
header.style.padding = "15px 5%";
nav.style.marginTop = "";
nav.style.flexWrap = "";
nav.style.justifyContent = "";
if (bannerTitle) bannerTitle.style.fontSize = "72px";
}
}
window.addEventListener("resize", handleResponsive);
handleResponsive();
// Кастомный курсор
(function customCursor(){
const cursor = document.getElementById('cursor');
if(!cursor) return;
let x = window.innerWidth / 2, y = window.innerHeight / 2;
let tx = x, ty = y;
let rafId;
function loop(){
x = x + (tx - x) * 0.18;
y = y + (ty - y) * 0.18;
cursor.style.transform = `translate(${x}px, ${y}px)`;
rafId = requestAnimationFrame(loop);
}
function move(e){
tx = e.clientX;
ty = e.clientY;
if(!rafId) loop();
cursor.classList.remove('hide');
}
function down(){
window.ZedRedLogger.log("Cursor active", 'interaction');
cursor.classList.add('active');
}
function up(){
window.ZedRedLogger.log("Cursor inactive", 'interaction');
cursor.classList.remove('active');
}
function leave(){
window.ZedRedLogger.log("Cursor hidden", 'interaction');
cursor.classList.add('hide');
cancelAnimationFrame(rafId);
rafId = null;
}
document.addEventListener('mousemove', move, {passive:true});
document.addEventListener('mousedown', down);
document.addEventListener('mouseup', up);
document.addEventListener('mouseleave', leave);
window.addEventListener('touchstart', () => { if(cursor) cursor.style.display = 'none'; }, {once:true});
})();
// Переключатель темы
(function toggles(){
// Переключатель темы (checkbox)
const switchEl = document.getElementById('themeSwitch');
const saved = localStorage.getItem('theme');
const initial = saved || 'dark';
document.documentElement.setAttribute('data-theme', initial);
if (switchEl) switchEl.checked = initial === 'light';
if (switchEl) switchEl.addEventListener('change', (e) => {
const next = e.target.checked ? 'light' : 'dark';
window.ZedRedLogger.log(`Theme switched to: ${next}`, 'theme');
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
// Обновляем иконки социальных сетей при смене темы
setTimeout(() => {
window.ZedRedLogger.log("Social icons updated for new theme", 'theme');
// Удаляем старые обработчики
document.querySelectorAll(".social-links a").forEach((link) => {
const coloredImg = link.querySelector("img:last-child");
if (coloredImg && coloredImg !== link.querySelector("img:first-child")) {
coloredImg.remove();
}
});
// Переинициализируем иконки
initSocialIcons();
}, 100);
});
})();
// Звёздное небо Canvas
(function stars(){
const canvas = document.getElementById('space');
if(!canvas) return;
const ctx = canvas.getContext('2d');
let dpr = Math.max(1, Math.min(2, window.devicePixelRatio || 1));
let w, h, stars = [], meteors = [], explosions = [], mouse = {x: 0.5, y: 0.5};
function clamp(v,min,max){ return Math.min(Math.max(v,min),max); }
function resize(){
w = canvas.width = Math.floor(window.innerWidth * dpr);
h = canvas.height = Math.floor(window.innerHeight * dpr);
canvas.style.width = window.innerWidth + 'px';
canvas.style.height = window.innerHeight + 'px';
ctx.setTransform(1,0,0,1,0,0);
ctx.scale(dpr, dpr);
initStars();
}
window.addEventListener('resize', resize);
function initStars(){
const count = Math.floor(clamp(window.innerWidth * window.innerHeight / 9000, 120, 260));
window.ZedRedLogger.log(`Stars initialized: ${count} stars`, 'animation');
stars = new Array(count).fill(0).map(()=> ({
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
r: Math.random() * 1.2 + .4,
tw: Math.random() * 2 * Math.PI,
sp: Math.random() * 0.6 + 0.3,
p: Math.random() * 0.6 + 0.2,
exploded: false
}));
}
function drawStars(t){
ctx.clearRect(0,0,window.innerWidth,window.innerHeight);
ctx.save();
// Рисуем только не взорванные звёзды
for (let i=0; i<stars.length; i++){
const s = stars[i];
if (s.exploded) continue; // Пропускаем взорванные звёзды
const tw = (Math.sin(t*0.0015 * s.sp + s.tw) + 1) * 0.5;
const alpha = 0.35 + tw * 0.65;
const px = s.x + (mouse.x - 0.5) * 16 * s.p;
const py = s.y + (mouse.y - 0.5) * 14 * s.p;
ctx.beginPath();
ctx.fillStyle = `rgba(255,255,255,${alpha.toFixed(3)})`;
ctx.arc(px, py, s.r, 0, Math.PI*2);
ctx.fill();
}
ctx.restore();
}
// Взрыв звезды при клике с реалистичной физикой
function explodeStar(x, y) {
const clickedStars = [];
const nearbyStars = [];
// Находим все звёзды в радиусе взрыва
for (let i = 0; i < stars.length; i++) {
const s = stars[i];
if (s.exploded) continue;
const px = s.x + (mouse.x - 0.5) * 16 * s.p;
const py = s.y + (mouse.y - 0.5) * 14 * s.p;
const distance = Math.sqrt((px - x) ** 2 + (py - y) ** 2);
if (distance < s.r * 8) {
clickedStars.push({star: s, distance: distance, x: px, y: py});
}
// Находим близкие звёзды для отталкивания
const nearbyDistance = Math.sqrt((px - x) ** 2 + (py - y) ** 2);
if (nearbyDistance < 100 && nearbyDistance > s.r * 8) {
nearbyStars.push({star: s, distance: nearbyDistance, x: px, y: py});
}
}
if (clickedStars.length === 0) return;
// Сортируем по расстоянию
clickedStars.sort((a, b) => a.distance - b.distance);
const mainStar = clickedStars[0];
// Рассчитываем силу взрыва
let explosionPower = 1;
let combinedEnergy = 0;
// Если очень близкие звёзды - объединяем энергию
if (clickedStars.length > 1) {
for (let star of clickedStars) {
combinedEnergy += star.star.r * (1 - star.distance / (star.star.r * 8));
}
explosionPower = Math.min(3, combinedEnergy); // Максимум в 3 раза сильнее
} else {
// Одна звезда - сила зависит от размера и расстояния
explosionPower = mainStar.star.r * (1 - mainStar.distance / (mainStar.star.r * 8));
}
// Взрываем все звёзды в радиусе
for (let clickedStar of clickedStars) {
clickedStar.star.exploded = true;
}
window.ZedRedLogger.log(`Star explosion: ${clickedStars.length} stars, power: ${explosionPower.toFixed(2)}`, 'animation');
// Создаём взрыв
const explosion = {
x: mainStar.x, y: mainStar.y, r: mainStar.star.r,
life: 0, maxLife: 10.0 * explosionPower,
particles: [],
rays: [],
power: explosionPower
};
// Создаём лучи света (в 5 раз меньше)
const rayCount = Math.floor(4 + explosionPower * 2);
for (let ray = 0; ray < rayCount; ray++) {
const angle = (ray / rayCount) * Math.PI * 2;
explosion.rays.push({
angle: angle,
length: 0,
maxLength: (25 + Math.random() * 15) / 5, // В 5 раз меньше
speed: (60 + Math.random() * 30) / 5, // В 5 раз медленнее
life: 0,
maxLife: (0.8 + Math.random() * 0.4) / 5, // В 5 раз короче
intensity: 1
});
}
// Частицы (в 5 раз меньше)
const particleCount = Math.floor(50 + explosionPower * 10);
for (let j = 0; j < particleCount; j++) {
explosion.particles.push({
x: mainStar.x, y: mainStar.y,
vx: (Math.random() - 0.5) * 200 / 5, // В 5 раз медленнее
vy: (Math.random() - 0.5) * 200 / 5,
life: 0, maxLife: (0.8 + Math.random() * 0.4) / 5, // В 5 раз короче
size: (Math.random() * 4 + 2) / 5, // В 5 раз меньше
color: Math.random() < 0.4 ? 'white' : Math.random() < 0.7 ? 'yellow' : 'orange'
});
}
// Крупные фрагменты (в 5 раз меньше)
for (let j = 0; j < 15; j++) {
explosion.particles.push({
x: mainStar.x, y: mainStar.y,
vx: (Math.random() - 0.5) * 120 / 5, // В 5 раз медленнее
vy: (Math.random() - 0.5) * 120 / 5,
life: 0, maxLife: (1.2 + Math.random() * 0.6) / 5, // В 5 раз короче
size: (Math.random() * 6 + 4) / 5, // В 5 раз меньше
color: Math.random() < 0.5 ? 'white' : 'yellow'
});
}
// Отталкиваем близкие звёзды
for (let nearbyStar of nearbyStars) {
const pushForce = explosionPower * 50;
const angle = Math.atan2(nearbyStar.y - mainStar.y, nearbyStar.x - mainStar.x);
nearbyStar.star.x += Math.cos(angle) * pushForce * 0.1;
nearbyStar.star.y += Math.sin(angle) * pushForce * 0.1;
}
// Если средняя дистанция и большая звезда - раскалываем на 2 части
if (clickedStars.length === 1 && mainStar.star.r > 1.5 && mainStar.distance > mainStar.star.r * 4) {
// Создаём второй взрыв рядом
const secondExplosion = {
x: mainStar.x + (Math.random() - 0.5) * 20,
y: mainStar.y + (Math.random() - 0.5) * 20,
r: mainStar.star.r * 0.7,
life: 0, maxLife: 5.0,
particles: [],
rays: [],
power: explosionPower * 0.5
};
// Лучи для второго взрыва
for (let ray = 0; ray < 4; ray++) {
const angle = (ray / 4) * Math.PI * 2;
secondExplosion.rays.push({
angle: angle,
length: 0,
maxLength: 15 + Math.random() * 10,
speed: 30 + Math.random() * 20,
life: 0,
maxLife: 0.6 + Math.random() * 0.3,
intensity: 1
});
}
explosions.push(secondExplosion);
}
explosions.push(explosion);
}
class Meteor {
constructor(){
const speedBase = Math.random() * 4 + 6;
this.x = window.innerWidth + 40;
this.y = Math.random()*window.innerHeight*0.5;
this.vx = -(speedBase + Math.random()*2);
this.vy = speedBase * 0.6 + Math.random()*1.5;
this.len = Math.random()*80 + 80;
this.life = 0; this.maxLife = 1.2 + Math.random()*0.8;
this.thick = Math.random()*1.2 + 0.6;
this.hue = 200 + Math.random()*70;
}
step(dt){
this.life += dt;
this.x += this.vx * dt * 60;
this.y += this.vy * dt * 60;
return (this.x > window.innerWidth + 100 || this.y > window.innerHeight + 100 || this.life > this.maxLife) ? false : true;
}
draw(){
const tailX = this.x - this.vx * this.len * 0.05;
const tailY = this.y - this.vy * this.len * 0.05;
const grad = ctx.createLinearGradient(this.x, this.y, tailX, tailY);
grad.addColorStop(0, `hsla(${this.hue}, 90%, 65%, .95)`);
grad.addColorStop(1, `hsla(${this.hue}, 90%, 65%, 0)`);
ctx.strokeStyle = grad;
ctx.lineWidth = this.thick;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(this.x, this.y);
ctx.lineTo(tailX, tailY);
ctx.stroke();
}
}
let last = performance.now(), meteorsActive = [];
function tick(now){
const dt = Math.min(0.033, (now - last)/1000); last = now;
drawStars(now);
if (meteorsActive.length < 3 && Math.random() < 0.015) {
window.ZedRedLogger.log("Meteor created", 'animation');
meteorsActive.push(new Meteor());
}
for (let i=meteorsActive.length-1; i>=0; i--){
const m = meteorsActive[i];
if (!m.step(dt)) { meteorsActive.splice(i,1); continue; }
m.draw();
}
// Взрывы звёзд
for (let i = explosions.length - 1; i >= 0; i--) {
const explosion = explosions[i];
explosion.life += dt;
if (explosion.life >= explosion.maxLife) {
explosions.splice(i, 1);
continue;
}
// Заполненный взрыв из 2 повернутых фигур (в 5 раз меньше)
if (explosion.rays) {
ctx.save();
const len = (34 + explosion.life * 40) / 5; // В 5 раз меньше
const centerX = explosion.x;
const centerY = explosion.y;
const alpha = 1.0 - (explosion.life / explosion.maxLife);
// Первая фигура (основная)
ctx.fillStyle = `rgba(255,255,255,${alpha * 0.8})`;
ctx.beginPath();
const outerRadius = len;
const innerRadius = len * 0.2;
const points = 4;
for (let i = 0; i < points * 2; i++) {
const angle = (i / (points * 2)) * Math.PI * 2;
const radius = i % 2 === 0 ? outerRadius : innerRadius;
const x = centerX + Math.cos(angle) * radius;
const y = centerY + Math.sin(angle) * radius;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.closePath();
ctx.fill();
// Вторая фигура (повернутая на 45 градусов)
ctx.fillStyle = `rgba(255,200,100,${alpha * 0.6})`;
ctx.beginPath();
const rotation = Math.PI / 4; // 45 градусов
for (let i = 0; i < points * 2; i++) {
const angle = (i / (points * 2)) * Math.PI * 2 + rotation;
const radius = i % 2 === 0 ? outerRadius * 0.8 : innerRadius * 0.8;
const x = centerX + Math.cos(angle) * radius;
const y = centerY + Math.sin(angle) * radius;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.closePath();
ctx.fill();
ctx.restore();
}
// Рисуем частицы взрыва
ctx.save();
for (let j = 0; j < explosion.particles.length; j++) {
const particle = explosion.particles[j];
particle.life += dt;
if (particle.life >= particle.maxLife) continue;
particle.x += particle.vx * dt;
particle.y += particle.vy * dt;
const alpha = 1 - (particle.life / particle.maxLife);
const size = particle.size * alpha;
// Цветные частицы
if (particle.color === 'white') {
ctx.fillStyle = `rgba(255, 255, 255, ${alpha})`;
} else if (particle.color === 'yellow') {
ctx.fillStyle = `rgba(255, 255, 100, ${alpha})`;
} else if (particle.color === 'orange') {
ctx.fillStyle = `rgba(255, 150, 50, ${alpha})`;
} else {
ctx.fillStyle = `rgba(255, 255, 255, ${alpha})`;
}
ctx.beginPath();
ctx.arc(particle.x, particle.y, size, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
// ВЗРЫВНАЯ ВОЛНА — кольцо с пульсацией
if (explosion.life > 0.1 && explosion.life < 0.8) {
ctx.save();
let waveRadius = (explosion.r * 2 + explosion.life * 30) / 5; // В 5 раз меньше
let waveAlpha = 0.6 * (1 - (explosion.life - 0.1) * 1.4);
let pulse = 1 + 0.3 * Math.sin(explosion.life * 20);
ctx.beginPath();
let segments = 24;
for (let i = 0; i <= segments; i++) {
let t = (i / segments) * Math.PI * 2;
let mod = 1 + (Math.random() - 0.5) * 0.1;
let radius = waveRadius * pulse * mod;
if (i === 0) {
ctx.moveTo(
explosion.x + Math.cos(t) * radius,
explosion.y + Math.sin(t) * radius
);
} else {
ctx.lineTo(
explosion.x + Math.cos(t) * radius,
explosion.y + Math.sin(t) * radius
);
}
}
ctx.strokeStyle = `rgba(255,255,255,${waveAlpha})`;
ctx.lineWidth = 2 + Math.sin(explosion.life * 15) * 1;
ctx.shadowColor = '#fff';
ctx.shadowBlur = 8;
ctx.stroke();
ctx.shadowBlur = 0;
ctx.restore();
}
// ВСПЫШКА — теперь с легким рандомным пульсом (в 5 раз меньше)
if (explosion.life < 0.25) {
ctx.save();
ctx.beginPath();
let flashRadius = (explosion.r * 3 * (1 + 0.18 * Math.sin(performance.now()/70 + explosion.life*6))) / 5; // В 5 раз меньше
let steps = 32;
ctx.moveTo(
explosion.x + Math.cos(0) * flashRadius * (1 + (Math.random() - 0.5)*0.07),
explosion.y + Math.sin(0) * flashRadius * (1 + (Math.random() - 0.5)*0.07)
);
for(let a=1; a<=steps; a++){
let theta = (a / steps) * Math.PI * 2;
let radius = flashRadius * (1 + (Math.random() - 0.5) * 0.13); // лёгкий шум
ctx.lineTo(
explosion.x + Math.cos(theta) * radius,
explosion.y + Math.sin(theta) * radius
);
}
let alpha = Math.max(0, 1 - explosion.life/0.21);
ctx.closePath();
ctx.fillStyle = `rgba(255,255,255,${alpha})`;
ctx.filter = 'blur(1px)';
ctx.fill();
ctx.filter = 'none';
ctx.restore();
}
// УДАРНАЯ ВОЛНА — кольцо-дуга с рандомной альфой (в 5 раз меньше)
if (explosion.life > 0.05 && explosion.life < 0.5) {
ctx.save();
let waveRadius = (explosion.r * 3.3 + explosion.life * 75) / 5; // В 5 раз меньше
ctx.beginPath();
let segments = 34;
for (let i = 0; i <= segments; i++) {
let t = (i / segments) * Math.PI * 2;
let mod = 1 + (Math.random() - 0.5) * 0.06; // лёгкие рваные края
if (i === 0) ctx.moveTo(
explosion.x + Math.cos(t) * waveRadius * mod,
explosion.y + Math.sin(t) * waveRadius * mod
);
else ctx.lineTo(
explosion.x + Math.cos(t) * waveRadius * mod,
explosion.y + Math.sin(t) * waveRadius * mod
);
}
let waveAlpha = 0.36 * (1 - (explosion.life - 0.08) * 2.3); // Fade out
ctx.strokeStyle = `rgba(255,255,255,${waveAlpha})`;
ctx.lineWidth = 1.3 + Math.sin(explosion.life * 10) * 0.9;
ctx.shadowColor = '#fff';
ctx.shadowBlur = 5;
ctx.stroke();
ctx.shadowBlur = 0;
ctx.restore();
}
}
requestAnimationFrame(tick);
}
window.addEventListener('mousemove', (e)=>{
mouse.x = e.clientX / window.innerWidth;
mouse.y = e.clientY / window.innerHeight;
}, {passive:true});
// Клик по звёздам для взрыва
canvas.addEventListener('click', (e) => {
const rect = canvas.getBoundingClientRect();
const x = (e.clientX - rect.left) * dpr;
const y = (e.clientY - rect.top) * dpr;
window.ZedRedLogger.log(`Star explosion at: (${Math.round(x)}, ${Math.round(y)})`, 'interaction');
explodeStar(x, y);
});
window.ZedRedLogger.log("Star field initialized", 'success');
resize(); requestAnimationFrame(tick);
})();
});