amirpoorazima commited on
Commit
8744985
·
verified ·
1 Parent(s): dee7b5a

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +238 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Virtual Ball
3
- emoji: 🏃
4
- colorFrom: yellow
5
- colorTo: indigo
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: virtual-ball
3
+ emoji: 🐳
4
+ colorFrom: gray
5
+ colorTo: pink
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,238 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
+ <title>Interactive Physics Ball</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
9
+ <style>
10
+ body {
11
+ overflow: hidden;
12
+ touch-action: none;
13
+ background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
14
+ }
15
+
16
+ #ball {
17
+ position: absolute;
18
+ border-radius: 50%;
19
+ box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
20
+ transition: transform 0.1s ease-out;
21
+ background: radial-gradient(circle at 30% 30%, #fff, #f0f0f0 40%, #d9d9d9 60%, #bfbfbf 80%);
22
+ }
23
+
24
+ #instructions {
25
+ background: rgba(0, 0, 0, 0.7);
26
+ backdrop-filter: blur(5px);
27
+ transition: all 0.3s ease;
28
+ }
29
+
30
+ #instructions.hidden {
31
+ opacity: 0;
32
+ pointer-events: none;
33
+ }
34
+
35
+ .bounce {
36
+ animation: bounce 0.5s cubic-bezier(0.28, 0.84, 0.42, 1);
37
+ }
38
+
39
+ @keyframes bounce {
40
+ 0%, 100% { transform: scale(1, 1) translateY(0); }
41
+ 10% { transform: scale(1.1, 0.9) translateY(0); }
42
+ 30% { transform: scale(0.9, 1.1) translateY(-20px); }
43
+ 50% { transform: scale(1.05, 0.95) translateY(0); }
44
+ 57% { transform: scale(1, 1) translateY(-7px); }
45
+ 64% { transform: scale(1, 1) translateY(0); }
46
+ }
47
+ </style>
48
+ </head>
49
+ <body class="h-screen w-full relative">
50
+ <div id="ball" class="w-16 h-16"></div>
51
+
52
+ <div id="instructions" class="fixed inset-0 flex flex-col items-center justify-center text-white p-6 z-10">
53
+ <div class="max-w-md bg-black bg-opacity-50 rounded-xl p-8 text-center">
54
+ <div class="text-4xl mb-6">
55
+ <i class="fas fa-mobile-alt animate-pulse"></i>
56
+ </div>
57
+ <h1 class="text-2xl font-bold mb-4">Physics Ball</h1>
58
+ <p class="mb-6">Shake or tilt your device to interact with the ball. The ball will bounce realistically based on physics simulation.</p>
59
+ <button id="startBtn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-6 rounded-full transition-all transform hover:scale-105">
60
+ Start Experience
61
+ </button>
62
+ </div>
63
+ </div>
64
+
65
+ <div class="absolute bottom-4 left-0 right-0 flex justify-center">
66
+ <div class="bg-black bg-opacity-50 text-white px-4 py-2 rounded-full text-sm flex items-center">
67
+ <i class="fas fa-info-circle mr-2"></i>
68
+ <span>Shake harder for more intense reactions!</span>
69
+ </div>
70
+ </div>
71
+
72
+ <script>
73
+ document.addEventListener('DOMContentLoaded', () => {
74
+ const ball = document.getElementById('ball');
75
+ const instructions = document.getElementById('instructions');
76
+ const startBtn = document.getElementById('startBtn');
77
+
78
+ let ballX = window.innerWidth / 2;
79
+ let ballY = window.innerHeight / 2;
80
+ let ballSize = 64;
81
+ let velocityX = 0;
82
+ let velocityY = 0;
83
+ let gravity = 0.2;
84
+ let friction = 0.99;
85
+ let bounce = 0.7;
86
+ let isSimulating = false;
87
+ let lastShakeTime = 0;
88
+ let shakeThreshold = 15;
89
+ let lastAcceleration = { x: 0, y: 0, z: 0 };
90
+
91
+ // Set initial ball position
92
+ ball.style.left = `${ballX - ballSize/2}px`;
93
+ ball.style.top = `${ballY - ballSize/2}px`;
94
+
95
+ // Start button handler
96
+ startBtn.addEventListener('click', () => {
97
+ instructions.classList.add('hidden');
98
+ startSimulation();
99
+ });
100
+
101
+ function startSimulation() {
102
+ if (isSimulating) return;
103
+ isSimulating = true;
104
+
105
+ // Request permission for iOS 13+ devices
106
+ if (typeof DeviceMotionEvent !== 'undefined' && typeof DeviceMotionEvent.requestPermission === 'function') {
107
+ DeviceMotionEvent.requestPermission()
108
+ .then(response => {
109
+ if (response === 'granted') {
110
+ window.addEventListener('devicemotion', handleMotion);
111
+ }
112
+ })
113
+ .catch(console.error);
114
+ } else {
115
+ window.addEventListener('devicemotion', handleMotion);
116
+ }
117
+
118
+ animate();
119
+ }
120
+
121
+ function handleMotion(event) {
122
+ const acceleration = event.accelerationIncludingGravity;
123
+ const now = Date.now();
124
+
125
+ // Calculate difference from previous acceleration
126
+ const deltaX = Math.abs(acceleration.x - lastAcceleration.x);
127
+ const deltaY = Math.abs(acceleration.y - lastAcceleration.y);
128
+ const deltaZ = Math.abs(acceleration.z - lastAcceleration.z);
129
+
130
+ // Check if it's a shake
131
+ if ((deltaX > shakeThreshold || deltaY > shakeThreshold || deltaZ > shakeThreshold) &&
132
+ now - lastShakeTime > 1000) {
133
+ lastShakeTime = now;
134
+
135
+ // Add random velocity for shake effect
136
+ velocityX += (Math.random() - 0.5) * 20;
137
+ velocityY += (Math.random() - 0.5) * 20;
138
+
139
+ // Visual feedback
140
+ ball.classList.add('bounce');
141
+ setTimeout(() => ball.classList.remove('bounce'), 500);
142
+ }
143
+
144
+ // Normal tilt handling
145
+ if (acceleration.x !== null) {
146
+ velocityX += acceleration.x * 0.5;
147
+ }
148
+ if (acceleration.y !== null) {
149
+ velocityY += -acceleration.y * 0.5;
150
+ }
151
+
152
+ lastAcceleration = {
153
+ x: acceleration.x,
154
+ y: acceleration.y,
155
+ z: acceleration.z
156
+ };
157
+ }
158
+
159
+ function animate() {
160
+ if (!isSimulating) return;
161
+
162
+ // Apply gravity
163
+ velocityY += gravity;
164
+
165
+ // Apply friction
166
+ velocityX *= friction;
167
+ velocityY *= friction;
168
+
169
+ // Update position
170
+ ballX += velocityX;
171
+ ballY += velocityY;
172
+
173
+ // Boundary collision - X axis
174
+ if (ballX - ballSize/2 < 0) {
175
+ ballX = ballSize/2;
176
+ velocityX = -velocityX * bounce;
177
+ } else if (ballX + ballSize/2 > window.innerWidth) {
178
+ ballX = window.innerWidth - ballSize/2;
179
+ velocityX = -velocityX * bounce;
180
+ }
181
+
182
+ // Boundary collision - Y axis
183
+ if (ballY - ballSize/2 < 0) {
184
+ ballY = ballSize/2;
185
+ velocityY = -velocityY * bounce;
186
+ } else if (ballY + ballSize/2 > window.innerHeight) {
187
+ ballY = window.innerHeight - ballSize/2;
188
+ velocityY = -velocityY * bounce;
189
+
190
+ // Extra effect when hitting the bottom
191
+ if (Math.abs(velocityY) > 2) {
192
+ ball.classList.add('bounce');
193
+ setTimeout(() => ball.classList.remove('bounce'), 500);
194
+ }
195
+ }
196
+
197
+ // Apply new position
198
+ ball.style.left = `${ballX - ballSize/2}px`;
199
+ ball.style.top = `${ballY - ballSize/2}px`;
200
+
201
+ // Color change based on velocity
202
+ const speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);
203
+ const hue = (speed * 2) % 360;
204
+ ball.style.background = `radial-gradient(circle at 30% 30%, hsl(${hue}, 100%, 90%), hsl(${hue}, 80%, 80%) 40%, hsl(${hue}, 60%, 70%) 60%, hsl(${hue}, 40%, 60%) 80%)`;
205
+
206
+ requestAnimationFrame(animate);
207
+ }
208
+
209
+ // Handle window resize
210
+ window.addEventListener('resize', () => {
211
+ // Keep ball on screen
212
+ if (ballX > window.innerWidth - ballSize/2) {
213
+ ballX = window.innerWidth - ballSize/2;
214
+ }
215
+ if (ballY > window.innerHeight - ballSize/2) {
216
+ ballY = window.innerHeight - ballSize/2;
217
+ }
218
+ });
219
+
220
+ // Click/tap to add random impulse
221
+ window.addEventListener('click', (e) => {
222
+ if (!isSimulating) return;
223
+
224
+ // Calculate direction from ball to click
225
+ const dx = e.clientX - ballX;
226
+ const dy = e.clientY - ballY;
227
+ const distance = Math.sqrt(dx * dx + dy * dy);
228
+
229
+ // Add velocity away from click point
230
+ if (distance < 200) {
231
+ velocityX += (ballX - e.clientX) / 20;
232
+ velocityY += (ballY - e.clientY) / 20;
233
+ }
234
+ });
235
+ });
236
+ </script>
237
+ <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=amirpoorazima/virtual-ball" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
238
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Virtual ball that interact with shaking phone