<!DOCTYPE html>
<html lang="uz">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To'g'onni buzish tajribasi: Daryo ekotizimini tiklash 3D</title>
<style>
body {
margin: 0;
overflow: hidden;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #87CEEB;
}
#ui-panel {
position: absolute;
top: 20px;
left: 20px;
background: rgba(15, 23, 42, 0.85);
color: #ffffff;
padding: 20px;
border-radius: 12px;
max-width: 340px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(8px);
}
h1 {
font-size: 18px;
margin: 0 0 10px 0;
color: #38bdf8;
}
p {
font-size: 13px;
line-height: 1.5;
color: #cbd5e1;
margin: 0 0 15px 0;
}
.btn-group {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
button {
flex: 1;
padding: 10px 12px;
border: none;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
transition: all 0.2s;
font-size: 13px;
}
#btn-remove {
background-color: #ef4444;
color: white;
}
#btn-remove:hover {
background-color: #dc2626;
}
#btn-reset {
background-color: #3b82f6;
color: white;
}
#btn-reset:hover {
background-color: #2563eb;
}
.stats {
background: rgba(255, 255, 255, 0.1);
padding: 12px;
border-radius: 8px;
font-size: 12px;
}
.stat-row {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
}
.stat-row:last-child {
margin-bottom: 0;
}
.val {
font-weight: bold;
color: #4ade80;
}
.controls-hint {
margin-top: 12px;
font-size: 11px;
color: #94a3b8;
text-align: center;
}
</style>
<!-- Three.js va OrbitControls CDN -->
<script src="https://cloudflare.com"></script>
<script src="https://jsdelivr.net"></script>
</head>
<body>
<div id="ui-panel">
<h1>To'g'onni buzish tajribasi (3D)</h1>
<p id="status-text">
<strong>Holat:</strong> To'g'on daryo oqimini to'sib turibdi. Yuqori qismda sun'iy suv ombori va cho'kindilar to'plangan, baliqlar migratsiyasi to'xtagan.
</p>
<div class="btn-group">
<button id="btn-remove" onclick="removeDam()">To'g'onni buzish</button>
<button id="btn-reset" onclick="resetSimulation()">Qayta tiklash</button>
</div>
<div class="stats">
<div class="stat-row">
<span>Oqim tezligi:</span>
<span class="val" id="stat-flow" style="color:#facc15;">Sekin (To'silgan)</span>
</div>
<div class="stat-row">
<span>Cho'kindilar harakati:</span>
<span class="val" id="stat-sediment" style="color:#f87171;">To'plangan</span>
</div>
<div class="stat-row">
<span>Baliqlar migratsiyasi:</span>
<span class="val" id="stat-fish" style="color:#f87171;">Cheklangan (20%)</span>
</div>
<div class="stat-row">
<span>Qirg'oq o'simliklari:</span>
<span class="val" id="stat-flora" style="color:#facc15;">Kamaygan</span>
</div>
</div>
<div class="controls-hint">
Sichqoncha: Aylantirish (Chap tugma) | Yaqinlashtirish (G'ildirak)
</div>
</div>
<script>
// 1. Sahna, Kamera va Renderer yaratish
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbae6fd);
scene.fog = new THREE.FogExp2(0xbae6fd, 0.012);
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(28, 22, 32);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.maxPolarAngle = Math.PI / 2 - 0.05;
// 2. Yorug'lik manbalari
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(20, 40, 20);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 2048;
dirLight.shadow.mapSize.height = 2048;
scene.add(dirLight);
// 3. Relyef (Vodiy va Daryo o'zani)
const groundGeo = new THREE.BoxGeometry(60, 2, 40);
const groundMat = new THREE.MeshStandardMaterial({ color: 0x4d7c0f, roughness: 0.9 });
// Chap qirg'oq
const leftBank = new THREE.Mesh(new THREE.BoxGeometry(60, 4, 15), groundMat);
leftBank.position.set(0, 1, -12.5);
leftBank.receiveShadow = true;
scene.add(leftBank);
// O'ng qirg'oq
const rightBank = new THREE.Mesh(new THREE.BoxGeometry(60, 4, 15), groundMat);
rightBank.position.set(0, 1, 12.5);
rightBank.receiveShadow = true;
scene.add(rightBank);
// Daryo tubi
const riverBed = new THREE.Mesh(
new THREE.BoxGeometry(60, 1, 12),
new THREE.MeshStandardMaterial({ color: 0x78350f, roughness: 1 })
);
riverBed.position.set(0, -0.5, 0);
riverBed.receiveShadow = true;
scene.add(riverBed);
// 4. Suv qatlamlari (Yuqori ombor va Quyi oqim)
const waterMat = new THREE.MeshStandardMaterial({
color: 0x0284c7,
transparent: true,
opacity: 0.78,
roughness: 0.1,
metalness: 0.1
});
// Yuqori qism suvi (To'g'ondan chapda: x = -30 dan 0 gacha)
const upstreamWater = new THREE.Mesh(new THREE.BoxGeometry(30, 3.2, 10.2), waterMat);
upstreamWater.position.set(-15, 1.5, 0);
scene.add(upstreamWater);
// Quyi qism suvi (To'g'ondan o'ngda: x = 0 dan 30 gacha)
const downstreamWater = new THREE.Mesh(new THREE.BoxGeometry(30, 1.0, 10.2), waterMat);
downstreamWater.position.set(15, 0.4, 0);
scene.add(downstreamWater);
// 5. To'g'on (Dam) bloklari (Buzilish animatsiyasi uchun bo'laklangan)
const damGroup = new THREE.Group();
const damBlocks = [];
const damMat = new THREE.MeshStandardMaterial({ color: 0x64748b, roughness: 0.7 });
for (let y = 0; y < 4; y++) {
for (let z = -4.5; z <= 4.5; z += 1.5) {
const block = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.95, 1.45), damMat);
block.position.set(0, 0.5 + y * 0.98, z);
block.castShadow = true;
block.receiveShadow = true;
block.userData = {
origPos: block.position.clone(),
vel: new THREE.Vector3(
(Math.random() * 0.15) + 0.05,
(Math.random() - 0.3) * 0.1,
(Math.random() - 0.5) * 0.1
),
rotVel: new THREE.Vector3(
Math.random() * 0.05,
Math.random() * 0.05,
Math.random() * 0.05
)
};
damGroup.add(block);
damBlocks.push(block);
}
}
scene.add(damGroup);
// 6. Cho'kindilar (Sediment zarralari)
const sediments = [];
const sedGeo = new THREE.DodecahedronGeometry(0.25, 0);
const sedMat = new THREE.MeshStandardMaterial({ color: 0xb45309 });
for (let i = 0; i < 80; i++) {
const sed = new THREE.Mesh(sedGeo, sedMat);
sed.position.set(
-2 - Math.random() * 14,
0.2 + Math.random() * 0.8,
(Math.random() - 0.5) * 8
);
sed.userData = { origPos: sed.position.clone() };
scene.add(sed);
sediments.push(sed);
}
// 7. Baliqlar (Ekotizim indikatori)
const fishes = [];
const fishGeo = new THREE.ConeGeometry(0.2, 0.7, 6);
fishGeo.rotateZ(-Math.PI / 2);
const fishMat = new THREE.MeshStandardMaterial({ color: 0xf97316 });
for (let i = 0; i < 18; i++) {
const fish = new THREE.Mesh(fishGeo, fishMat);
// Dastlab baliqlar faqat quyi oqimda (x > 2) suzadi
fish.position.set(
3 + Math.random() * 24,
0.5,
(Math.random() - 0.5) * 7
);
fish.userData = {
speed: 0.04 + Math.random() * 0.04,
offset: Math.random() * Math.PI * 2
};
scene.add(fish);
fishes.push(fish);
}
// 8. Qirg'oq daraxtlari (Tabiiy flora tiklanishi)
const trees = [];
function createTree(x, z, isRestoredTree) {
const treeGroup = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.2, 1.2, 6),
new THREE.MeshStandardMaterial({ color: 0x5c4033 })
);
trunk.position.y = 0.6;
const leaves = new THREE.Mesh(
new THREE.ConeGeometry(0.9, 2.2, 7),
new THREE.MeshStandardMaterial({ color: isRestoredTree ? 0x16a34a : 0x15803d })
);
leaves.position.y = 2.0;
treeGroup.add(trunk, leaves);
treeGroup.position.set(x, 3, z);
if (isRestoredTree) {
treeGroup.scale.set(0.01, 0.01, 0.01); // Dastlab ko'rinmaydi, keyin o'sadi
}
scene.add(treeGroup);
trees.push({ mesh: treeGroup, isRestoredTree });
}
// Mavjud daraxtlar
Используйте код с осторожностью.
for (let i = 0; i < 20; i++) {
const x = (Math.random() - 0.5) * 54;
const z = (Math.random() > 0.5 ? 1 : -1) * (8 + Math.random() * 10);
createTree(x, z, false);
}
// To’g’on buzilgandan keyin o’sadigan yangi daraxtlar
for (let i = 0; i < 25; i++) {
const x = (Math.random() - 0.5) * 50;
const z = (Math.random() > 0.5 ? 1 : -1) * (6.2 + Math.random() * 4);
createTree(x, z, true);
}
// 9. Holat o’zgaruvchilari va Boshqaruv funksiyalari
let isDamRemoved = false;
let restorationProgress = 0; // 0 dan 1 gacha
function removeDam() {
if (isDamRemoved) return;
isDamRemoved = true;
document.getElementById(‘status-text’).innerHTML =
“Holat: To’g’on buzildi! Suv sathi tenglashmoqda, ozuqaviy cho’kindilar quyi oqimga o’tmoqda va baliqlar yuqori oqimga erkin suzib o’tmoqda.”;
document.getElementById(‘stat-flow’).textContent = “Tabiiy va erkin”;
document.getElementById(‘stat-flow’).style.color = “#4ade80”;
document.getElementById(‘stat-sediment’).textContent = “Tabiiy taqsimlanmoqda”;
document.getElementById(‘stat-sediment’).style.color = “#4ade80”;
document.getElementById(‘stat-fish’).textContent = “To’liq tiklandi (100%)”;
document.getElementById(‘stat-fish’).style.color = “#4ade80”;
document.getElementById(‘stat-flora’).textContent = “Faol tiklanmoqda”;
document.getElementById(‘stat-flora’).style.color = “#4ade80”;
}
function resetSimulation() {
isDamRemoved = false;
restorationProgress = 0;
// To’g’on bloklarini joyiga qaytarish
damBlocks.forEach(block => {
block.position.copy(block.userData.origPos);
block.rotation.set(0, 0, 0);
block.visible = true;
});
// Suv sathini qaytarish
upstreamWater.scale.y = 1;
upstreamWater.position.y = 1.5;
downstreamWater.scale.y = 1;
downstreamWater.position.y = 0.4;
// Cho’kindilarni qaytarish
sediments.forEach(sed => {
sed.position.copy(sed.userData.origPos);
});
// Baliqlarni quyi oqimga qaytarish
fishes.forEach(fish => {
fish.position.x = 3 + Math.random() * 24;
fish.position.y = 0.5;
});
// Yangi daraxtlarni kichraytirish
trees.forEach(t => {
if (t.isRestoredTree) t.mesh.scale.set(0.01, 0.01, 0.01);
});
document.getElementById(‘status-text’).innerHTML =
“Holat: To’g’on daryo oqimini to’sib turibdi. Yuqori qismda sun’iy suv ombori va cho’kindilar to’plangan, baliqlar migratsiyasi to’xtagan.”;
document.getElementById(‘stat-flow’).textContent = “Sekin (To’silgan)”;
document.getElementById(‘stat-flow’).style.color = “#facc15”;
document.getElementById(‘stat-sediment’).textContent = “To’plangan”;
document.getElementById(‘stat-sediment’).style.color = “#f87171”;
document.getElementById(‘stat-fish’).textContent = “Cheklangan (20%)”;
document.getElementById(‘stat-fish’).style.color = “#f87171”;
document.getElementById(‘stat-flora’).textContent = “Kamaygan”;
document.getElementById(‘stat-flora’).style.color = “#facc15”;
}
// 10. Animatsiya sikli
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
if (isDamRemoved) {
if (restorationProgress < 1) {
restorationProgress += 0.004;
}
// To’g’on bloklarining qulashi va yo’qolishi
damBlocks.forEach(block => {
if (block.visible) {
block.position.add(block.userData.vel);
block.rotation.x += block.userData.rotVel.x;
block.rotation.y += block.userData.rotVel.y;
block.userData.vel.y -= 0.008; // Gravitatsiya
if (block.position.y < -2) {
block.visible = false;
}
}
});
// Yuqori va quyi suv sathlarining tabiiy holatda tenglashishi
const targetUpScale = THREE.MathUtils.lerp(1, 0.45, restorationProgress);
upstreamWater.scale.y = targetUpScale;
upstreamWater.position.y = (3.2 * targetUpScale) / 2;
const targetDownScale = THREE.MathUtils.lerp(1, 1.44, restorationProgress);
downstreamWater.scale.y = targetDownScale;
downstreamWater.position.y = (1.0 * targetDownScale) / 2;
// Cho’kindilarning oqim bo’ylab tarqalishi
sediments.forEach(sed => {
sed.position.x += 0.08;
if (sed.position.x > 28) {
sed.position.x = -28;
}
});
// Qirg’oqdagi yangi daraxtlarning o’sishi
trees.forEach(t => {
if (t.isRestoredTree && t.mesh.scale.x < 1) {
const s = Math.min(1, t.mesh.scale.x + 0.005);
t.mesh.scale.set(s, s, s);
}
});
}
// Baliqlar harakati
fishes.forEach(fish => {
// To’g’on buzilganda baliqlar yuqori oqimga (-28 gacha) o’ta oladi
const minX = isDamRemoved ? -28 : 2.0;
fish.position.x -= fish.userData.speed;
fish.position.z += Math.sin(time * 3 + fish.userData.offset) * 0.015;
fish.position.y = isDamRemoved ? 0.65 : 0.5;
if (fish.position.x < minX) {
fish.position.x = 28;
}
});
controls.update();
renderer.render(scene, camera);
}
// Oyna o’lchami o’zgarganda moslashish
window.addEventListener(‘resize’, () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();