-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
2474 lines (2134 loc) · 94.5 KB
/
Copy pathapp.js
File metadata and controls
2474 lines (2134 loc) · 94.5 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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Monument Explorer - Advanced JavaScript with 3D effects, animations and interactions - FIXED VERSION
// Wait for DOM to be fully loaded
document.addEventListener('DOMContentLoaded', () => {
// Initialize application
initApp();
});
// Main initialization function
function initApp() {
try {
// Show loading screen
const loadingScreen = document.getElementById('loading-screen');
const loadingStatus = document.querySelector('.loading-status');
if (!loadingScreen) {
console.error('Loading screen element not found');
// Skip loading screen and initialize directly
initializeComponents();
return;
}
// Simulate loading process
const loadingMessages = [
'Initializing 3D Engine',
'Generating Monument Models',
'Calculating Light Physics',
'Preparing Materials',
'Creating Dynamic Shadows',
'Finalizing Experience'
];
let messageIndex = 0;
const messageInterval = setInterval(() => {
if (loadingStatus) {
loadingStatus.textContent = loadingMessages[messageIndex];
messageIndex = (messageIndex + 1) % loadingMessages.length;
}
}, 600);
// Create particle effects for loading screen
try {
createParticles('.particle-system', 50);
} catch (error) {
console.warn('Particle creation failed:', error);
}
// Simulate loading complete after 3.5 seconds
setTimeout(() => {
clearInterval(messageInterval);
hideLoadingScreen(loadingScreen);
initializeComponents();
}, 3500);
} catch (error) {
console.error('Initialization error:', error);
// Fallback: hide loading and initialize anyway
initializeComponents();
}
}
function hideLoadingScreen(loadingScreen) {
try {
loadingScreen.classList.add('hidden');
setTimeout(() => {
loadingScreen.style.display = 'none';
}, 600);
} catch (error) {
console.error('Error hiding loading screen:', error);
loadingScreen.style.display = 'none';
}
}
function initializeComponents() {
const components = [
initNavigation,
initCustomCursor,
initScrollAnimations,
initHeroSection,
initMonumentsSection,
initGamesSection,
initLaboratorySection,
initTimelineSection,
initAchievementsSection,
initAudioControls,
initThemeToggle,
initNewsletterSection,
initCreditsSection
];
components.forEach((initFunc, index) => {
try {
if (typeof initFunc === 'function') {
initFunc();
}
} catch (error) {
console.error(`Error in component ${index}:`, error);
}
});
}
// ===== CUSTOM CURSOR =====
function initCustomCursor() {
const cursor = document.getElementById('custom-cursor');
const cursorTrail = document.querySelector('.cursor-trail');
const cursorGlow = document.querySelector('.cursor-glow');
// Only enable custom cursor for devices with fine pointer (mouse)
if (window.matchMedia('(pointer: fine)').matches) {
document.addEventListener('mousemove', (e) => {
cursor.style.left = `${e.clientX}px`;
cursor.style.top = `${e.clientY}px`;
// Scale effect on interactive elements
const target = e.target.closest('button, a, [role="button"], .clickable, .floating-monument, .monument-card, .game-card');
if (target) {
cursorTrail.style.transform = 'scale(1.5)';
cursorGlow.style.transform = 'scale(2)';
cursorGlow.style.opacity = '0.8';
} else {
cursorTrail.style.transform = 'scale(0.8)';
cursorGlow.style.transform = 'scale(1)';
cursorGlow.style.opacity = '0.5';
}
});
// Handle cursor leaving the window
document.addEventListener('mouseleave', () => {
cursor.style.opacity = '0';
});
document.addEventListener('mouseenter', () => {
cursor.style.opacity = '1';
});
// Handle click effect
document.addEventListener('mousedown', () => {
cursorTrail.style.transform = 'scale(0.6)';
});
document.addEventListener('mouseup', () => {
cursorTrail.style.transform = 'scale(0.8)';
});
}
}
// ===== NAVIGATION =====
function initNavigation() {
const navLinks = document.querySelectorAll('.nav-link');
const sections = document.querySelectorAll('section');
// Handle navigation click with improved performance
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
// Immediate visual feedback
navLinks.forEach(l => l.classList.remove('active'));
link.classList.add('active');
// Smooth scroll with better timing
const targetPosition = targetSection.offsetTop - 80;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Optimized scroll handler
let scrollTimer = null;
window.addEventListener('scroll', () => {
if (scrollTimer !== null) {
clearTimeout(scrollTimer);
}
scrollTimer = setTimeout(() => {
updateActiveNav();
updateNavbarStyle();
}, 10);
});
function updateActiveNav() {
let currentSection = '';
const scrollPos = window.pageYOffset;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.clientHeight;
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
currentSection = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').substring(1) === currentSection) {
link.classList.add('active');
}
});
}
function updateNavbarStyle() {
const navbar = document.getElementById('main-nav');
if (window.scrollY > 50) {
navbar.style.padding = `8px 16px`;
navbar.style.boxShadow = 'var(--shadow-lg)';
navbar.style.backgroundColor = 'rgba(var(--color-surface-rgb), 0.95)';
} else {
navbar.style.padding = `12px 16px`;
navbar.style.boxShadow = 'var(--shadow-md)';
navbar.style.backgroundColor = 'rgba(var(--color-surface-rgb), 0.8)';
}
}
}
// ===== THEME TOGGLE =====
function initThemeToggle() {
const themeToggle = document.getElementById('theme-toggle');
// Check for saved theme preference or use device theme
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.documentElement.setAttribute('data-color-scheme', savedTheme);
} else {
// Check if user prefers dark mode
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (prefersDarkMode) {
document.documentElement.setAttribute('data-color-scheme', 'dark');
}
}
// Toggle theme on click
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-color-scheme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-color-scheme', newTheme);
localStorage.setItem('theme', newTheme);
// Enhanced transition effect
document.body.style.transition = 'background-color 0.5s ease-out, color 0.5s ease-out';
setTimeout(() => {
document.body.style.transition = '';
}, 500);
showNotification(`Switched to ${newTheme} mode`, 'info');
});
}
// ===== AUDIO CONTROLS =====
function initAudioControls() {
const audioToggle = document.getElementById('audio-toggle');
const audioPanel = document.getElementById('audio-panel');
// Audio state
const audioState = {
masterVolume: 70,
ambientSounds: true,
uiSounds: true,
narration: true,
muted: false
};
// Toggle audio panel
audioToggle.addEventListener('click', (e) => {
e.stopPropagation();
audioPanel.classList.toggle('active');
// Enhanced visual feedback
if (audioPanel.classList.contains('active')) {
audioToggle.style.background = 'var(--color-primary)';
audioToggle.style.color = 'var(--color-btn-primary-text)';
} else {
audioToggle.style.background = '';
audioToggle.style.color = '';
}
// Play UI sound
if (audioState.uiSounds && !audioState.muted) {
playUISound('click');
}
});
// Handle master volume
const masterVolume = document.getElementById('master-volume');
if (masterVolume) {
masterVolume.addEventListener('input', (e) => {
audioState.masterVolume = parseInt(e.target.value);
updateAudioSettings();
});
}
// Handle audio options
const ambientSounds = document.getElementById('ambient-sounds');
const uiSounds = document.getElementById('ui-sounds');
const narration = document.getElementById('narration');
[ambientSounds, uiSounds, narration].forEach(control => {
if (control) {
control.addEventListener('change', (e) => {
audioState[e.target.id.replace('-', '')] = e.target.checked;
updateAudioSettings();
if (audioState.uiSounds && !audioState.muted) {
playUISound('toggle');
}
});
}
});
// Close audio panel when clicking outside
document.addEventListener('click', (e) => {
if (!audioPanel.contains(e.target) && !audioToggle.contains(e.target)) {
audioPanel.classList.remove('active');
audioToggle.style.background = '';
audioToggle.style.color = '';
}
});
function updateAudioSettings() {
console.log('Audio settings updated:', audioState);
}
function playUISound(type) {
console.log(`Playing UI sound: ${type}`);
}
}
// ===== SCROLL ANIMATIONS =====
function initScrollAnimations() {
const sections = document.querySelectorAll('section');
const sectionHeaders = document.querySelectorAll('.section-header');
// Elements to animate on scroll
const elementsToAnimate = [
'.monument-card',
'.game-card',
'.achievement-card',
'.sun-controls',
'.material-analysis',
'.experiment-zone',
'.time-navigator',
'.time-portal-viewer'
];
// Enhanced observer callback
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Enhanced staggered animations
if (entry.target.classList.contains('monument-card')) {
const index = Array.from(document.querySelectorAll('.monument-card')).indexOf(entry.target);
entry.target.style.transitionDelay = `${0.15 * index}s`;
entry.target.style.animationDelay = `${0.15 * index}s`;
}
if (entry.target.classList.contains('game-card')) {
const index = Array.from(document.querySelectorAll('.game-card')).indexOf(entry.target);
entry.target.style.transitionDelay = `${0.1 * index}s`;
}
if (entry.target.classList.contains('achievement-card')) {
const index = Array.from(document.querySelectorAll('.achievement-card')).indexOf(entry.target);
entry.target.style.transitionDelay = `${0.1 * index}s`;
}
}
});
};
// Create Intersection Observer with better threshold
const observer = new IntersectionObserver(observerCallback, {
threshold: 0.1,
rootMargin: '-50px'
});
// Observe elements
sectionHeaders.forEach(header => observer.observe(header));
elementsToAnimate.forEach(selector => {
document.querySelectorAll(selector).forEach(element => {
observer.observe(element);
});
});
// Enhanced parallax effect
let parallaxTimer = null;
window.addEventListener('scroll', () => {
if (parallaxTimer !== null) {
clearTimeout(parallaxTimer);
}
parallaxTimer = setTimeout(() => {
const scrollPosition = window.pageYOffset;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollPosition > sectionTop - window.innerHeight &&
scrollPosition < sectionTop + sectionHeight) {
const parallaxElements = section.querySelectorAll('.monument-3d, .monument-model, .game-3d-scene, .sample-3d');
parallaxElements.forEach(element => {
const speed = 0.03;
const yPos = (scrollPosition - sectionTop) * speed;
const currentTransform = element.style.transform || '';
if (currentTransform.includes('rotateX') && currentTransform.includes('rotateY')) {
// Preserve existing rotation while adding parallax
element.style.transform = currentTransform.replace(/translateY\([^)]*\)/, '') + ` translateY(${yPos}px)`;
} else {
element.style.transform = `translateY(${yPos}px) rotateX(15deg) rotateY(20deg)`;
}
});
}
});
}, 5);
});
}
// ===== HERO SECTION =====
function initHeroSection() {
const startJourneyBtn = document.getElementById('start-journey');
const vrExperienceBtn = document.getElementById('virtual-reality');
const floatingMonuments = document.querySelectorAll('.floating-monument');
const heroSubtitle = document.querySelector('.hero-subtitle');
// Staggered animation for each word in the hero subtitle
if (heroSubtitle) {
const words = heroSubtitle.querySelectorAll('span');
words.forEach((word, i) => {
setTimeout(() => {
word.classList.add('animated');
}, 120 * i);
});
}
window.addEventListener('DOMContentLoaded', initHeroSection);
// Start journey button
if (startJourneyBtn) {
startJourneyBtn.addEventListener('click', () => {
window.scrollTo({
top: document.getElementById('monuments').offsetTop - 80,
behavior: 'smooth'
});
createParticleExplosion(startJourneyBtn, 50);
});
}
// VR experience button
if (vrExperienceBtn) {
vrExperienceBtn.addEventListener('click', () => {
showNotification('VR Experience coming soon! Prepare for immersive monument exploration.', 'info');
});
}
// Enhanced floating monuments interaction
floatingMonuments.forEach(monument => {
const label = monument.querySelector('.monument-label');
const glow = monument.querySelector('.monument-glow');
monument.addEventListener('mouseenter', () => {
// Enhanced glow effect
if (glow) {
glow.style.opacity = '1';
glow.style.filter = 'blur(15px)';
glow.style.transform = 'rotateX(90deg) translateZ(-10px) scale(1.5)';
}
// Enhanced label effect
if (label) {
label.style.transform = 'translateX(-50%) scale(1.3)';
label.style.color = 'var(--color-primary)';
label.style.fontWeight = 'var(--font-weight-bold)';
label.style.textShadow = '0 4px 15px rgba(0,0,0,0.5)';
}
// Add bounce animation to monument
monument.style.animation = 'float 1s infinite ease-in-out';
});
monument.addEventListener('mouseleave', () => {
// Reset effects
if (glow) {
glow.style.opacity = '0.6';
glow.style.filter = 'blur(5px)';
glow.style.transform = 'rotateX(90deg) translateZ(-10px) scale(1)';
}
if (label) {
label.style.transform = 'translateX(-50%) scale(1)';
label.style.color = 'var(--color-text)';
label.style.fontWeight = '';
label.style.textShadow = '';
}
// Reset animation
monument.style.animation = '';
});
monument.addEventListener('click', () => {
const monumentId = monument.getAttribute('data-monument');
// Enhanced click feedback
monument.style.transform = 'translateZ(100px) scale(1.5)';
setTimeout(() => {
monument.style.transform = '';
}, 300);
// Navigate to corresponding monument
setTimeout(() => {
const monumentCard = document.querySelector(`.monument-card[data-monument="${monumentId}"]`);
if (monumentCard) {
window.scrollTo({
top: monumentCard.offsetTop - 100,
behavior: 'smooth'
});
// Enhanced highlight effect
monumentCard.style.transform = 'translateY(-20px) scale(1.05)';
monumentCard.style.boxShadow = '0 20px 40px rgba(var(--color-primary-rgb), 0.3)';
monumentCard.style.borderColor = 'var(--color-primary)';
setTimeout(() => {
monumentCard.style.transform = '';
monumentCard.style.boxShadow = '';
monumentCard.style.borderColor = '';
}, 2500);
} else {
window.scrollTo({
top: document.getElementById('monuments').offsetTop - 80,
behavior: 'smooth'
});
}
}, 300);
});
});
// Add particle effects to hero background
createParticles('.hero-background', 30);
}
document.querySelectorAll('.expand-btn').forEach(btn => {
btn.addEventListener('click', function() {
const panel = btn.parentElement.nextElementSibling;
const expanded = btn.getAttribute('aria-expanded') === 'true';
if (!expanded) {
// Expand panel
btn.setAttribute('aria-expanded', 'true');
panel.setAttribute('aria-hidden', 'false');
panel.classList.add('expanded');
// Animate max-height to scrollHeight for smooth expansion
panel.style.maxHeight = panel.scrollHeight + 'px';
panel.style.opacity = '1';
// Confetti burst
const confetti = panel.querySelector('.confetti');
confetti.innerHTML = '';
for (let i = 0; i < 20; i++) {
const piece = document.createElement('div');
piece.className = 'confetti-piece';
// Random colors from palette
const colors = ['#d4af37', '#b08d57', '#ede3c6', '#a89f91'];
piece.style.background = colors[i % colors.length];
// Random X/Y translations for burst effect
const x = (Math.random() - 0.5) * 160; // -80 to +80 px
const y = (Math.random() - 1) * 120; // -120 to 0 px (upwards)
piece.style.setProperty('--x', `${x}px`);
piece.style.setProperty('--y', `${y}px`);
// Random animation delay for natural effect
piece.style.animationDelay = (Math.random() * 0.2) + 's';
confetti.appendChild(piece);
}
// Remove confetti after animation ends
setTimeout(() => {
confetti.innerHTML = '';
}, 1000);
} else {
// Collapse panel
btn.setAttribute('aria-expanded', 'false');
panel.setAttribute('aria-hidden', 'true');
// Animate collapse by setting max-height to 0
panel.style.maxHeight = '0';
panel.style.opacity = '0';
// Remove shiny animation class after transition
panel.addEventListener('transitionend', function handler() {
panel.classList.remove('expanded');
panel.removeEventListener('transitionend', handler);
});
}
});
});
// ===== MONUMENTS SECTION =====
function initMonumentsSection() {
const sunSlider = document.getElementById('sun-time');
const sunIndicator = document.querySelector('.sun-indicator');
const lightValue = document.getElementById('light-value');
const shadowValue = document.getElementById('shadow-value');
const monumentCards = document.querySelectorAll('.monument-card');
const exploreBtns = document.querySelectorAll('.explore-btn');
// Enhanced sun position and lighting
if (sunSlider) {
sunSlider.addEventListener('input', (e) => {
const time = parseFloat(e.target.value);
updateLighting(time);
});
// Initialize with default time (noon)
updateLighting(12);
}
// Enhanced explore monument buttons
exploreBtns.forEach(btn => {
btn.addEventListener('click', () => {
const monumentCard = btn.closest('.monument-card');
const monumentName = monumentCard.querySelector('h3').textContent;
showNotification(`Exploring ${monumentName} in immersive detail mode`, 'success');
// Enhanced zoom effect
const model = monumentCard.querySelector('.monument-3d');
const particles = monumentCard.querySelector('.monument-particles');
// Create exploration particles
createParticleExplosion(btn, 30);
// Enhanced 3D model interaction
if (model) {
model.style.transform = 'rotateX(25deg) rotateY(80deg) scale(1.3)';
model.style.filter = 'brightness(1.2) contrast(1.1)';
}
// Add particle effect to monument
if (particles) {
particles.innerHTML = '';
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.style.position = 'absolute';
particle.style.width = '3px';
particle.style.height = '3px';
particle.style.backgroundColor = 'var(--color-primary)';
particle.style.borderRadius = '50%';
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
particle.style.animation = 'float 2s infinite ease-in-out';
particle.style.animationDelay = Math.random() * 2 + 's';
particles.appendChild(particle);
}
}
setTimeout(() => {
if (model) {
model.style.transform = '';
model.style.filter = '';
}
if (particles) particles.innerHTML = '';
}, 3000);
});
});
// Enhanced interactive 3D models
monumentCards.forEach(card => {
const model = card.querySelector('.monument-3d');
if (model) {
model.addEventListener('mousemove', (e) => {
const rect = model.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Enhanced rotation calculation
const rotateY = ((x / rect.width) - 0.5) * 60;
const rotateX = ((y / rect.height) - 0.5) * -30;
model.style.transform = `rotateX(${15 + rotateX}deg) rotateY(${20 + rotateY}deg) scale(1.05)`;
model.style.filter = 'brightness(1.1)';
});
model.addEventListener('mouseleave', () => {
model.style.transform = 'rotateX(15deg) rotateY(20deg)';
model.style.filter = '';
});
}
});
// Smooth collapsible logic for modal section
const headerBtn = document.querySelector('.modal-header');
const modalContent = document.getElementById('materialModal');
headerBtn.addEventListener('click', () => {
const expanded = headerBtn.getAttribute('aria-expanded') === 'true';
headerBtn.setAttribute('aria-expanded', String(!expanded));
modalContent.setAttribute('aria-hidden', String(expanded));
if (!expanded) {
modalContent.classList.add('open');
// Set max-height to scrollHeight for smooth expand
modalContent.style.maxHeight = modalContent.scrollHeight + 'px';
modalContent.style.opacity = '1';
} else {
// Collapse: set max-height to 0 for smooth collapse
modalContent.style.maxHeight = '0';
modalContent.style.opacity = '0';
// Remove .open after transition for accessibility
setTimeout(() => {
if (modalContent.style.maxHeight === '0px') {
modalContent.classList.remove('open');
}
}, 800); // match transition duration
}
});
// Optional: adjust max-height on window resize if open
window.addEventListener('resize', () => {
if (modalContent.classList.contains('open')) {
modalContent.style.maxHeight = modalContent.scrollHeight + 'px';
}
});
// Enhanced lighting update function
function updateLighting(time) {
let angle = 0;
if (time >= 6 && time <= 18) {
angle = ((time - 6) / 12) * 180;
} else if (time < 6) {
angle = 0;
} else {
angle = 180;
}
// Enhanced sun indicator with glow
if (sunIndicator) {
sunIndicator.style.transform = `rotate(${angle}deg) translateY(-52px) rotate(-${angle}deg)`;
}
// Enhanced light calculation
let lightIntensity = 0;
if (time >= 6 && time <= 18) {
const midday = 12;
const distanceFromMidday = Math.abs(time - midday);
lightIntensity = Math.max(20, 100 - (distanceFromMidday * 15));
} else {
lightIntensity = Math.max(5, 30 - Math.abs(time - 12) * 3);
}
// Enhanced shadow calculation
let shadowLength = '';
let shadowIntensity = 1;
if (time >= 11 && time <= 13) {
shadowLength = 'Very Short';
shadowIntensity = 0.6;
} else if ((time >= 9 && time < 11) || (time > 13 && time <= 15)) {
shadowLength = 'Short';
shadowIntensity = 0.8;
} else if ((time >= 7 && time < 9) || (time > 15 && time <= 17)) {
shadowLength = 'Medium';
shadowIntensity = 1.0;
} else if ((time >= 5 && time < 7) || (time > 17 && time <= 19)) {
shadowLength = 'Long';
shadowIntensity = 1.3;
} else {
shadowLength = 'Very Long';
shadowIntensity = 1.5;
}
// Update display with enhanced feedback
if (lightValue) lightValue.textContent = `${Math.round(lightIntensity)}%`;
if (shadowValue) shadowValue.textContent = shadowLength;
// Enhanced monument lighting effects
const monuments = document.querySelectorAll('.monument-3d');
monuments.forEach(monument => {
const shadow = monument.querySelector('.monument-shadow');
const container = monument.closest('.monument-3d-container');
if (shadow) {
shadow.style.width = `${60 + (shadowIntensity * 20)}%`;
shadow.style.filter = `blur(${3 + shadowIntensity * 4}px)`;
shadow.style.opacity = Math.min(0.8, 0.2 + shadowIntensity * 0.4);
// Add shadow direction based on sun position
const shadowOffset = (angle - 90) * 0.2;
shadow.style.transform = `translateX(calc(-50% + ${shadowOffset}px)) rotateX(90deg)`;
}
// Enhanced background transitions
if (container) {
let bgColor = '';
let ambientLight = '';
if (time >= 5 && time < 8) {
// Dawn
bgColor = 'linear-gradient(135deg, var(--time-dawn), var(--color-background))';
ambientLight = 'drop-shadow(0 0 10px rgba(242, 166, 94, 0.3))';
} else if (time >= 8 && time < 17) {
// Day
bgColor = 'linear-gradient(135deg, var(--time-noon), var(--color-background))';
ambientLight = 'drop-shadow(0 0 15px rgba(255, 255, 253, 0.4))';
} else if (time >= 17 && time < 20) {
// Dusk
bgColor = 'linear-gradient(135deg, var(--time-dusk), var(--color-background))';
ambientLight = 'drop-shadow(0 0 10px rgba(221, 85, 85, 0.3))';
} else {
// Night
bgColor = 'linear-gradient(135deg, var(--time-night), var(--color-background))';
ambientLight = 'drop-shadow(0 0 8px rgba(31, 64, 104, 0.5))';
}
container.style.background = bgColor;
monument.style.filter = ambientLight;
}
});
// Update sun indicator glow
if (sunIndicator) {
if (lightIntensity > 50) {
sunIndicator.style.boxShadow = `0 0 ${lightIntensity * 0.3}px rgba(255, 215, 0, ${lightIntensity / 100})`;
} else {
sunIndicator.style.boxShadow = `0 0 5px rgba(200, 200, 255, 0.3)`;
}
}
}
}
// Enhanced Material Database with IS Code Properties
const materials = {
'red-sandstone': {
name: 'Red Sandstone',
description: 'Durable, weather-resistant, easy to carve. Iron oxide gives red color, excellent workability. Perfect for forts, palaces, and decorative elements.',
properties: { density: 76, hardness: 60, durability: 85 },
values: { density: '2.3 g/cm³', hardness: '6/10', durability: 'Very High' },
color: '#8B4513',
isProperties: {
compressiveStrength: 65, // MPa as per IS 1121-1
transverseStrength: 6.5, // MPa as per IS 1121-2
tensileStrength: 3.9, // MPa as per IS 1121-3
waterAbsorption: 0.65 // % as per IS 1124
}
},
'white-marble': {
name: 'White Marble',
description: 'Beautiful finish, cool to touch, translucent. Metamorphic limestone that takes fine polish. Ideal for decorative elements, inlay work, and mausoleums.',
properties: { density: 90, hardness: 70, durability: 65 },
values: { density: '2.7 g/cm³', hardness: '7/10', durability: 'High' },
color: '#FFFAFA',
isProperties: {
compressiveStrength: 70, // MPa as per IS 1121-1
transverseStrength: 9.1, // MPa as per IS 1121-2
tensileStrength: 5.6, // MPa as per IS 1121-3
waterAbsorption: 0.35 // % as per IS 1124
}
},
'granite': {
name: 'Granite',
description: 'Extremely hard, long-lasting, earthquake-resistant. Crystalline structure with minimal water absorption. Perfect for temple construction and load-bearing structures.',
properties: { density: 95, hardness: 90, durability: 95 },
values: { density: '2.8 g/cm³', hardness: '9/10', durability: 'Exceptional' },
color: '#708090',
isProperties: {
compressiveStrength: 95, // MPa as per IS 1121-1
transverseStrength: 14.3, // MPa as per IS 1121-2
tensileStrength: 9.5, // MPa as per IS 1121-3
waterAbsorption: 0.15 // % as per IS 1124
}
},
'lime-mortar': {
name: 'Lime Mortar',
description: 'Traditional binding material made from limestone with breathable and self-healing properties. Used extensively in historic structures across India.',
properties: { density: 65, hardness: 40, durability: 75 },
values: { density: '1.7 g/cm³', hardness: '4/10', durability: 'High' },
color: '#E8E4D8',
isProperties: {
compressiveStrength: 3.5, // MPa as per IS 1121-1
transverseStrength: 1.2, // MPa as per IS 1121-2
tensileStrength: 0.8, // MPa as per IS 1121-3
waterAbsorption: 12.5 // % as per IS 1124
}
},
'egg-white-lime': {
name: 'Egg White Lime',
description: 'Advanced mortar using egg whites as binding agent, creating extremely durable finishes. Used in Chettinad architecture and fine detail work.',
properties: { density: 68, hardness: 45, durability: 85 },
values: { density: '1.8 g/cm³', hardness: '4.5/10', durability: 'Very High' },
color: '#F5F5F0',
isProperties: {
compressiveStrength: 4.2, // MPa as per IS 1121-1
transverseStrength: 1.5, // MPa as per IS 1121-2
tensileStrength: 1.1, // MPa as per IS 1121-3
waterAbsorption: 9.8 // % as per IS 1124
}
},
'honey-lime': {
name: 'Honey Lime',
description: 'Ancient mortar incorporating honey for water-resistant and flexible binding. Used in traditional construction for water-resistant applications.',
properties: { density: 70, hardness: 42, durability: 80 },
values: { density: '1.75 g/cm³', hardness: '4.2/10', durability: 'High' },
color: '#E6D9B8',
isProperties: {
compressiveStrength: 3.8, // MPa as per IS 1121-1
transverseStrength: 1.4, // MPa as per IS 1121-2
tensileStrength: 1.0, // MPa as per IS 1121-3
waterAbsorption: 8.5 // % as per IS 1124
}
},
'coconut-fiber-lime': {
name: 'Coconut Fiber Lime',
description: 'Lime mortar reinforced with coconut fibers for enhanced tensile strength. Traditional in coastal regions for structures requiring flexibility.',
properties: { density: 62, hardness: 38, durability: 82 },
values: { density: '1.65 g/cm³', hardness: '3.8/10', durability: 'Very High' },
color: '#D9C9A3',
isProperties: {
compressiveStrength: 3.2, // MPa as per IS 1121-1
transverseStrength: 1.8, // MPa as per IS 1121-2
tensileStrength: 1.4, // MPa as per IS 1121-3
waterAbsorption: 10.2 // % as per IS 1124
}
},
'teak-wood': {
name: 'Teak Wood',
description: 'Durable hardwood with natural termite resistance. Extensively used in Kerala architecture and temple construction for its longevity.',
properties: { density: 55, hardness: 65, durability: 90 },
values: { density: '0.65 g/cm³', hardness: '6.5/10', durability: 'Exceptional' },
color: '#B68D4C',
isProperties: {
compressiveStrength: 58, // MPa as per IS 1121-1
transverseStrength: 95, // MPa as per IS 1121-2
tensileStrength: 100, // MPa as per IS 1121-3
waterAbsorption: 7.0 // % as per IS 1124
}
}
};
// IS Code Helper Functions
// IS 1121-1 compliant compressive strength values
function getISCompressiveStrength(material) {
return materials[material].isProperties.compressiveStrength;
}
// IS 1121-2 compliant transverse strength values
function getISTransverseStrength(material) {
return materials[material].isProperties.transverseStrength;
}
// IS 1121-3 compliant tensile strength values
function getISTensileStrength(material) {
return materials[material].isProperties.tensileStrength;
}
// IS 1124:1974 compliant water absorption values
function getISWaterAbsorption(material) {
return materials[material].isProperties.waterAbsorption;
}
// Complete IS code test implementation
function runISCodeTest() {
if (!currentMaterial || !materials[currentMaterial]) {
showNotification('Please select a material first', 'error');
return;
}
const materialData = materials[currentMaterial];
const testResults = {
'compressive': calculateCompressiveStrength(),
'transverse': calculateTransverseStrength(),
'tensile': calculateTensileStrength(),
'waterAbsorption': getISWaterAbsorption(currentMaterial)
};
let isTestResult = `📋 IS Code Test Results for ${materialData.name}:\n\n`;
isTestResult += `• IS 1121-1: Compressive Strength = ${testResults.compressive.toFixed(2)} MPa\n`;
isTestResult += `• IS 1121-2: Transverse Strength = ${testResults.transverse.toFixed(2)} MPa\n`;
isTestResult += `• IS 1121-3: Tensile Strength = ${testResults.tensile.toFixed(2)} MPa\n`;
isTestResult += `• IS 1124: Water Absorption = ${testResults.waterAbsorption.toFixed(2)}%\n\n`;
// Check compliance with IS requirements
const complianceStatus = checkISCodeCompliance(testResults);
isTestResult += `🔍 IS Code Compliance Status:\n`;
for (const [test, status] of Object.entries(complianceStatus)) {
isTestResult += `• ${test}: ${status.compliant ? '✅ Compliant' : '❌ Non-compliant'} (${status.details})\n`;