Add 2 files
Browse files- README.md +6 -4
- index.html +226 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: yellow
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ball-v0-1
|
| 3 |
+
emoji: 🐳
|
| 4 |
colorFrom: yellow
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,226 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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>3D Bouncing Balls in Sphere</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
body {
|
| 12 |
+
margin: 0;
|
| 13 |
+
overflow: hidden;
|
| 14 |
+
font-family: 'Inter', sans-serif;
|
| 15 |
+
}
|
| 16 |
+
#info {
|
| 17 |
+
position: absolute;
|
| 18 |
+
top: 20px;
|
| 19 |
+
left: 20px;
|
| 20 |
+
color: white;
|
| 21 |
+
background: rgba(0,0,0,0.7);
|
| 22 |
+
padding: 10px;
|
| 23 |
+
border-radius: 5px;
|
| 24 |
+
z-index: 100;
|
| 25 |
+
}
|
| 26 |
+
#controls {
|
| 27 |
+
position: absolute;
|
| 28 |
+
bottom: 20px;
|
| 29 |
+
left: 20px;
|
| 30 |
+
color: white;
|
| 31 |
+
background: rgba(0,0,0,0.7);
|
| 32 |
+
padding: 10px;
|
| 33 |
+
border-radius: 5px;
|
| 34 |
+
z-index: 100;
|
| 35 |
+
}
|
| 36 |
+
canvas {
|
| 37 |
+
display: block;
|
| 38 |
+
}
|
| 39 |
+
</style>
|
| 40 |
+
</head>
|
| 41 |
+
<body class="bg-gray-900">
|
| 42 |
+
<div id="info" class="text-sm">
|
| 43 |
+
<h1 class="text-xl font-bold mb-2">Bouncing Balls in Sphere</h1>
|
| 44 |
+
<p>Use mouse to rotate view</p>
|
| 45 |
+
<p>Scroll to zoom in/out</p>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<div id="controls">
|
| 49 |
+
<div class="flex items-center mb-2">
|
| 50 |
+
<label class="text-white mr-2">Ball Count:</label>
|
| 51 |
+
<input type="range" id="ballCount" min="10" max="200" value="50" class="w-32">
|
| 52 |
+
<span id="ballCountValue" class="ml-2">50</span>
|
| 53 |
+
</div>
|
| 54 |
+
<div class="flex items-center mb-2">
|
| 55 |
+
<label class="text-white mr-2">Bounce Speed:</label>
|
| 56 |
+
<input type="range" id="bounceSpeed" min="0.1" max="2" step="0.1" value="1" class="w-32">
|
| 57 |
+
<span id="bounceSpeedValue" class="ml-2">1.0</span>
|
| 58 |
+
</div>
|
| 59 |
+
<div class="flex items-center">
|
| 60 |
+
<label class="text-white mr-2">Sphere Opacity:</label>
|
| 61 |
+
<input type="range" id="sphereOpacity" min="0" max="1" step="0.1" value="0.2" class="w-32">
|
| 62 |
+
<span id="sphereOpacityValue" class="ml-2">0.2</span>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
<script>
|
| 67 |
+
// Scene setup
|
| 68 |
+
const scene = new THREE.Scene();
|
| 69 |
+
scene.background = new THREE.Color(0x111111);
|
| 70 |
+
|
| 71 |
+
// Camera setup
|
| 72 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 73 |
+
camera.position.z = 30;
|
| 74 |
+
|
| 75 |
+
// Renderer setup
|
| 76 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 77 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 78 |
+
renderer.shadowMap.enabled = true;
|
| 79 |
+
document.body.appendChild(renderer.domElement);
|
| 80 |
+
|
| 81 |
+
// Orbit controls for camera interaction
|
| 82 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 83 |
+
controls.enableDamping = true;
|
| 84 |
+
controls.dampingFactor = 0.05;
|
| 85 |
+
|
| 86 |
+
// Lighting
|
| 87 |
+
const ambientLight = new THREE.AmbientLight(0x404040);
|
| 88 |
+
scene.add(ambientLight);
|
| 89 |
+
|
| 90 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 91 |
+
directionalLight.position.set(1, 1, 1);
|
| 92 |
+
directionalLight.castShadow = true;
|
| 93 |
+
scene.add(directionalLight);
|
| 94 |
+
|
| 95 |
+
// Create the transparent sphere
|
| 96 |
+
const sphereRadius = 15;
|
| 97 |
+
const sphereGeometry = new THREE.SphereGeometry(sphereRadius, 32, 32);
|
| 98 |
+
const sphereMaterial = new THREE.MeshPhongMaterial({
|
| 99 |
+
color: 0x3399ff,
|
| 100 |
+
transparent: true,
|
| 101 |
+
opacity: 0.2,
|
| 102 |
+
wireframe: true,
|
| 103 |
+
side: THREE.DoubleSide
|
| 104 |
+
});
|
| 105 |
+
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
|
| 106 |
+
scene.add(sphere);
|
| 107 |
+
|
| 108 |
+
// Create bouncing balls
|
| 109 |
+
const balls = [];
|
| 110 |
+
const ballGeometry = new THREE.SphereGeometry(0.5, 16, 16);
|
| 111 |
+
const ballMaterial = new THREE.MeshPhongMaterial({
|
| 112 |
+
color: 0xff5555,
|
| 113 |
+
shininess: 100
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
function createBalls(count) {
|
| 117 |
+
// Remove existing balls
|
| 118 |
+
balls.forEach(ball => scene.remove(ball));
|
| 119 |
+
balls.length = 0;
|
| 120 |
+
|
| 121 |
+
// Create new balls
|
| 122 |
+
for (let i = 0; i < count; i++) {
|
| 123 |
+
const ball = new THREE.Mesh(ballGeometry, ballMaterial.clone());
|
| 124 |
+
ball.castShadow = true;
|
| 125 |
+
ball.receiveShadow = true;
|
| 126 |
+
|
| 127 |
+
// Random position inside sphere
|
| 128 |
+
const radius = Math.random() * (sphereRadius - 1);
|
| 129 |
+
const theta = Math.random() * Math.PI * 2;
|
| 130 |
+
const phi = Math.random() * Math.PI;
|
| 131 |
+
|
| 132 |
+
ball.position.x = radius * Math.sin(phi) * Math.cos(theta);
|
| 133 |
+
ball.position.y = radius * Math.sin(phi) * Math.sin(theta);
|
| 134 |
+
ball.position.z = radius * Math.cos(phi);
|
| 135 |
+
|
| 136 |
+
// Random velocity
|
| 137 |
+
ball.userData.velocity = new THREE.Vector3(
|
| 138 |
+
(Math.random() - 0.5) * 0.2,
|
| 139 |
+
(Math.random() - 0.5) * 0.2,
|
| 140 |
+
(Math.random() - 0.5) * 0.2
|
| 141 |
+
);
|
| 142 |
+
|
| 143 |
+
// Random color
|
| 144 |
+
ball.material.color.setHSL(Math.random(), 0.7, 0.5);
|
| 145 |
+
|
| 146 |
+
scene.add(ball);
|
| 147 |
+
balls.push(ball);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
// Initial creation
|
| 152 |
+
createBalls(50);
|
| 153 |
+
|
| 154 |
+
// Animation variables
|
| 155 |
+
let bounceSpeed = 1.0;
|
| 156 |
+
|
| 157 |
+
// Animation loop
|
| 158 |
+
function animate() {
|
| 159 |
+
requestAnimationFrame(animate);
|
| 160 |
+
|
| 161 |
+
// Update balls
|
| 162 |
+
balls.forEach(ball => {
|
| 163 |
+
// Move ball
|
| 164 |
+
ball.position.x += ball.userData.velocity.x * bounceSpeed;
|
| 165 |
+
ball.position.y += ball.userData.velocity.y * bounceSpeed;
|
| 166 |
+
ball.position.z += ball.userData.velocity.z * bounceSpeed;
|
| 167 |
+
|
| 168 |
+
// Check collision with sphere boundary
|
| 169 |
+
const distance = ball.position.length();
|
| 170 |
+
if (distance > sphereRadius - 1) {
|
| 171 |
+
// Calculate normal vector from sphere center to ball
|
| 172 |
+
const normal = ball.position.clone().normalize();
|
| 173 |
+
|
| 174 |
+
// Reflect velocity
|
| 175 |
+
ball.userData.velocity.reflect(normal);
|
| 176 |
+
|
| 177 |
+
// Add some randomness to bounce
|
| 178 |
+
ball.userData.velocity.add(
|
| 179 |
+
new THREE.Vector3(
|
| 180 |
+
(Math.random() - 0.5) * 0.02,
|
| 181 |
+
(Math.random() - 0.5) * 0.02,
|
| 182 |
+
(Math.random() - 0.5) * 0.02
|
| 183 |
+
)
|
| 184 |
+
);
|
| 185 |
+
|
| 186 |
+
// Dampen velocity slightly
|
| 187 |
+
ball.userData.velocity.multiplyScalar(0.98);
|
| 188 |
+
}
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
+
// Update controls
|
| 192 |
+
controls.update();
|
| 193 |
+
|
| 194 |
+
// Render scene
|
| 195 |
+
renderer.render(scene, camera);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
animate();
|
| 199 |
+
|
| 200 |
+
// Handle window resize
|
| 201 |
+
window.addEventListener('resize', () => {
|
| 202 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 203 |
+
camera.updateProjectionMatrix();
|
| 204 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 205 |
+
});
|
| 206 |
+
|
| 207 |
+
// UI controls
|
| 208 |
+
document.getElementById('ballCount').addEventListener('input', (e) => {
|
| 209 |
+
const count = parseInt(e.target.value);
|
| 210 |
+
document.getElementById('ballCountValue').textContent = count;
|
| 211 |
+
createBalls(count);
|
| 212 |
+
});
|
| 213 |
+
|
| 214 |
+
document.getElementById('bounceSpeed').addEventListener('input', (e) => {
|
| 215 |
+
bounceSpeed = parseFloat(e.target.value);
|
| 216 |
+
document.getElementById('bounceSpeedValue').textContent = bounceSpeed.toFixed(1);
|
| 217 |
+
});
|
| 218 |
+
|
| 219 |
+
document.getElementById('sphereOpacity').addEventListener('input', (e) => {
|
| 220 |
+
const opacity = parseFloat(e.target.value);
|
| 221 |
+
sphere.material.opacity = opacity;
|
| 222 |
+
document.getElementById('sphereOpacityValue').textContent = opacity.toFixed(1);
|
| 223 |
+
});
|
| 224 |
+
</script>
|
| 225 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=zackrr/ball-v0-1" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
|
| 226 |
+
</html>
|