Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +398 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 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: hypnotic-flocking
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 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,398 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ial-scale=1.0">
|
| 6 |
+
<title>Hypnotic Flocking Simulation</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
margin: 0;
|
| 11 |
+
overflow: hidden;
|
| 12 |
+
background: #000;
|
| 13 |
+
}
|
| 14 |
+
canvas {
|
| 15 |
+
display: block;
|
| 16 |
+
}
|
| 17 |
+
.controls {
|
| 18 |
+
position: absolute;
|
| 19 |
+
top: 20px;
|
| 20 |
+
left: 20px;
|
| 21 |
+
z-index: 100;
|
| 22 |
+
color: white;
|
| 23 |
+
background: rgba(0, 0, 0, 0.7);
|
| 24 |
+
padding: 15px;
|
| 25 |
+
border-radius: 10px;
|
| 26 |
+
font-family: 'Arial', sans-serif;
|
| 27 |
+
}
|
| 28 |
+
.particle {
|
| 29 |
+
position: absolute;
|
| 30 |
+
border-radius: 50%;
|
| 31 |
+
pointer-events: none;
|
| 32 |
+
}
|
| 33 |
+
</style>
|
| 34 |
+
</head>
|
| 35 |
+
<body>
|
| 36 |
+
<canvas id="flockCanvas"></canvas>
|
| 37 |
+
<div class="controls">
|
| 38 |
+
<h1 class="text-2xl font-bold mb-4 text-purple-400">Hypnotic Flocking</h1>
|
| 39 |
+
<div class="grid grid-cols-2 gap-4">
|
| 40 |
+
<div>
|
| 41 |
+
<label class="block text-sm font-medium text-cyan-300">Alignment</label>
|
| 42 |
+
<input type="range" id="alignment" min="0" max="2" step="0.01" value="1" class="w-full">
|
| 43 |
+
</div>
|
| 44 |
+
<div>
|
| 45 |
+
<label class="block text-sm font-medium text-cyan-300">Cohesion</label>
|
| 46 |
+
<input type="range" id="cohesion" min="0" max="2" step="0.01" value="1" class="w-full">
|
| 47 |
+
</div>
|
| 48 |
+
<div>
|
| 49 |
+
<label class="block text-sm font-medium text-cyan-300">Separation</label>
|
| 50 |
+
<input type="range" id="separation" min="0" max="2" step="0.01" value="1.5" class="w-full">
|
| 51 |
+
</div>
|
| 52 |
+
<div>
|
| 53 |
+
<label class="block text-sm font-medium text-cyan-300">Particle Count</label>
|
| 54 |
+
<input type="range" id="particleCount" min="50" max="1000" step="10" value="500" class="w-full">
|
| 55 |
+
</div>
|
| 56 |
+
<div>
|
| 57 |
+
<label class="block text-sm font-medium text-cyan-300">Trail Length</label>
|
| 58 |
+
<input type="range" id="trailLength" min="0" max="1" step="0.01" value="0.05" class="w-full">
|
| 59 |
+
</div>
|
| 60 |
+
<div>
|
| 61 |
+
<label class="block text-sm font-medium text-cyan-300">Color Mode</label>
|
| 62 |
+
<select id="colorMode" class="w-full bg-gray-800 text-white rounded p-1">
|
| 63 |
+
<option value="velocity">Velocity</option>
|
| 64 |
+
<option value="distance">Distance</option>
|
| 65 |
+
<option value="rainbow">Rainbow</option>
|
| 66 |
+
<option value="pulse">Pulse</option>
|
| 67 |
+
</select>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
<button id="resetBtn" class="mt-4 px-4 py-2 bg-purple-600 hover:bg-purple-700 rounded text-white">Reset Simulation</button>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 75 |
+
const canvas = document.getElementById('flockCanvas');
|
| 76 |
+
const ctx = canvas.getContext('2d');
|
| 77 |
+
|
| 78 |
+
// Set canvas to full window size
|
| 79 |
+
canvas.width = window.innerWidth;
|
| 80 |
+
canvas.height = window.innerHeight;
|
| 81 |
+
|
| 82 |
+
// Flocking parameters
|
| 83 |
+
let params = {
|
| 84 |
+
alignment: 1,
|
| 85 |
+
cohesion: 1,
|
| 86 |
+
separation: 1.5,
|
| 87 |
+
particleCount: 500,
|
| 88 |
+
trailLength: 0.05,
|
| 89 |
+
colorMode: 'velocity',
|
| 90 |
+
mouseInfluence: true,
|
| 91 |
+
mouseRadius: 100,
|
| 92 |
+
mouseStrength: 5
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
// Initialize controls
|
| 96 |
+
document.getElementById('alignment').addEventListener('input', (e) => {
|
| 97 |
+
params.alignment = parseFloat(e.target.value);
|
| 98 |
+
});
|
| 99 |
+
|
| 100 |
+
document.getElementById('cohesion').addEventListener('input', (e) => {
|
| 101 |
+
params.cohesion = parseFloat(e.target.value);
|
| 102 |
+
});
|
| 103 |
+
|
| 104 |
+
document.getElementById('separation').addEventListener('input', (e) => {
|
| 105 |
+
params.separation = parseFloat(e.target.value);
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
document.getElementById('particleCount').addEventListener('input', (e) => {
|
| 109 |
+
params.particleCount = parseInt(e.target.value);
|
| 110 |
+
resetSimulation();
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
document.getElementById('trailLength').addEventListener('input', (e) => {
|
| 114 |
+
params.trailLength = parseFloat(e.target.value);
|
| 115 |
+
});
|
| 116 |
+
|
| 117 |
+
document.getElementById('colorMode').addEventListener('change', (e) => {
|
| 118 |
+
params.colorMode = e.target.value;
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
document.getElementById('resetBtn').addEventListener('click', () => {
|
| 122 |
+
resetSimulation();
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
// Mouse position
|
| 126 |
+
let mouseX = null;
|
| 127 |
+
let mouseY = null;
|
| 128 |
+
|
| 129 |
+
canvas.addEventListener('mousemove', (e) => {
|
| 130 |
+
mouseX = e.clientX;
|
| 131 |
+
mouseY = e.clientY;
|
| 132 |
+
});
|
| 133 |
+
|
| 134 |
+
canvas.addEventListener('mouseout', () => {
|
| 135 |
+
mouseX = null;
|
| 136 |
+
mouseY = null;
|
| 137 |
+
});
|
| 138 |
+
|
| 139 |
+
// Particle class
|
| 140 |
+
class Particle {
|
| 141 |
+
constructor() {
|
| 142 |
+
this.reset();
|
| 143 |
+
this.history = [];
|
| 144 |
+
this.maxHistory = 5;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
reset() {
|
| 148 |
+
this.x = Math.random() * canvas.width;
|
| 149 |
+
this.y = Math.random() * canvas.height;
|
| 150 |
+
this.vx = (Math.random() - 0.5) * 2;
|
| 151 |
+
this.vy = (Math.random() - 0.5) * 2;
|
| 152 |
+
this.size = 2 + Math.random() * 3;
|
| 153 |
+
this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
|
| 154 |
+
this.baseHue = Math.random() * 360;
|
| 155 |
+
this.pulsePhase = Math.random() * Math.PI * 2;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
update(particles) {
|
| 159 |
+
// Store position history for trails
|
| 160 |
+
this.history.unshift({x: this.x, y: this.y});
|
| 161 |
+
if (this.history.length > this.maxHistory) {
|
| 162 |
+
this.history.pop();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// Apply flocking rules
|
| 166 |
+
this.flock(particles);
|
| 167 |
+
|
| 168 |
+
// Apply mouse influence
|
| 169 |
+
if (mouseX !== null && mouseY !== null && params.mouseInfluence) {
|
| 170 |
+
const dx = mouseX - this.x;
|
| 171 |
+
const dy = mouseY - this.y;
|
| 172 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 173 |
+
|
| 174 |
+
if (distance < params.mouseRadius) {
|
| 175 |
+
const angle = Math.atan2(dy, dx);
|
| 176 |
+
const force = (params.mouseRadius - distance) / params.mouseRadius * params.mouseStrength;
|
| 177 |
+
this.vx += Math.cos(angle) * force * 0.1;
|
| 178 |
+
this.vy += Math.sin(angle) * force * 0.1;
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Update position
|
| 183 |
+
this.x += this.vx;
|
| 184 |
+
this.y += this.vy;
|
| 185 |
+
|
| 186 |
+
// Apply boundary conditions (wrap around)
|
| 187 |
+
if (this.x < 0) this.x = canvas.width;
|
| 188 |
+
if (this.x > canvas.width) this.x = 0;
|
| 189 |
+
if (this.y < 0) this.y = canvas.height;
|
| 190 |
+
if (this.y > canvas.height) this.y = 0;
|
| 191 |
+
|
| 192 |
+
// Apply friction
|
| 193 |
+
this.vx *= 0.98;
|
| 194 |
+
this.vy *= 0.98;
|
| 195 |
+
|
| 196 |
+
// Limit speed
|
| 197 |
+
const speed = Math.sqrt(this.vx * this.vx + this.vy * this.vy);
|
| 198 |
+
const maxSpeed = 3;
|
| 199 |
+
if (speed > maxSpeed) {
|
| 200 |
+
this.vx = (this.vx / speed) * maxSpeed;
|
| 201 |
+
this.vy = (this.vy / speed) * maxSpeed;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
// Update pulse phase for color animation
|
| 205 |
+
this.pulsePhase += 0.02;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
flock(particles) {
|
| 209 |
+
let alignmentX = 0;
|
| 210 |
+
let alignmentY = 0;
|
| 211 |
+
let cohesionX = 0;
|
| 212 |
+
let cohesionY = 0;
|
| 213 |
+
let separationX = 0;
|
| 214 |
+
let separationY = 0;
|
| 215 |
+
|
| 216 |
+
let neighborCount = 0;
|
| 217 |
+
const perceptionRadius = 100;
|
| 218 |
+
|
| 219 |
+
for (let other of particles) {
|
| 220 |
+
if (other === this) continue;
|
| 221 |
+
|
| 222 |
+
const dx = other.x - this.x;
|
| 223 |
+
const dy = other.y - this.y;
|
| 224 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 225 |
+
|
| 226 |
+
if (distance < perceptionRadius) {
|
| 227 |
+
neighborCount++;
|
| 228 |
+
|
| 229 |
+
// Alignment: steer toward average heading of neighbors
|
| 230 |
+
alignmentX += other.vx;
|
| 231 |
+
alignmentY += other.vy;
|
| 232 |
+
|
| 233 |
+
// Cohesion: steer toward average position of neighbors
|
| 234 |
+
cohesionX += other.x;
|
| 235 |
+
cohesionY += other.y;
|
| 236 |
+
|
| 237 |
+
// Separation: avoid crowding neighbors
|
| 238 |
+
if (distance < 30) {
|
| 239 |
+
separationX -= dx / distance;
|
| 240 |
+
separationY -= dy / distance;
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
if (neighborCount > 0) {
|
| 246 |
+
// Apply alignment
|
| 247 |
+
alignmentX /= neighborCount;
|
| 248 |
+
alignmentY /= neighborCount;
|
| 249 |
+
const alignMag = Math.sqrt(alignmentX * alignmentX + alignmentY * alignmentY);
|
| 250 |
+
if (alignMag > 0) {
|
| 251 |
+
alignmentX = (alignmentX / alignMag) * params.alignment;
|
| 252 |
+
alignmentY = (alignmentY / alignMag) * params.alignment;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Apply cohesion
|
| 256 |
+
cohesionX /= neighborCount;
|
| 257 |
+
cohesionY /= neighborCount;
|
| 258 |
+
cohesionX -= this.x;
|
| 259 |
+
cohesionY -= this.y;
|
| 260 |
+
const cohereMag = Math.sqrt(cohesionX * cohesionX + cohesionY * cohesionY);
|
| 261 |
+
if (cohereMag > 0) {
|
| 262 |
+
cohesionX = (cohesionX / cohereMag) * params.cohesion;
|
| 263 |
+
cohesionY = (cohesionY / cohereMag) * params.cohesion;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// Apply separation
|
| 267 |
+
const separateMag = Math.sqrt(separationX * separationX + separationY * separationY);
|
| 268 |
+
if (separateMag > 0) {
|
| 269 |
+
separationX = (separationX / separateMag) * params.separation;
|
| 270 |
+
separationY = (separationY / separateMag) * params.separation;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// Combine all forces
|
| 274 |
+
this.vx += alignmentX + cohesionX + separationX;
|
| 275 |
+
this.vy += alignmentY + cohesionY + separationY;
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
draw(ctx) {
|
| 280 |
+
// Determine color based on mode
|
| 281 |
+
let color;
|
| 282 |
+
const speed = Math.sqrt(this.vx * this.vx + this.vy * this.vy);
|
| 283 |
+
|
| 284 |
+
switch(params.colorMode) {
|
| 285 |
+
case 'velocity':
|
| 286 |
+
color = `hsl(${(speed * 50) % 360}, 100%, 50%)`;
|
| 287 |
+
break;
|
| 288 |
+
case 'distance':
|
| 289 |
+
const avgDist = this.calculateAverageDistance();
|
| 290 |
+
color = `hsl(${(avgDist * 0.5) % 360}, 100%, 50%)`;
|
| 291 |
+
break;
|
| 292 |
+
case 'rainbow':
|
| 293 |
+
color = `hsl(${(this.baseHue + Date.now() * 0.01) % 360}, 100%, 50%)`;
|
| 294 |
+
break;
|
| 295 |
+
case 'pulse':
|
| 296 |
+
const pulseValue = Math.sin(this.pulsePhase) * 0.5 + 0.5;
|
| 297 |
+
color = `hsl(${this.baseHue}, 100%, ${pulseValue * 50 + 30}%)`;
|
| 298 |
+
break;
|
| 299 |
+
default:
|
| 300 |
+
color = this.color;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Draw trail
|
| 304 |
+
if (this.history.length > 1) {
|
| 305 |
+
ctx.beginPath();
|
| 306 |
+
ctx.moveTo(this.history[0].x, this.history[0].y);
|
| 307 |
+
|
| 308 |
+
for (let i = 1; i < this.history.length; i++) {
|
| 309 |
+
const alpha = i / this.history.length * params.trailLength;
|
| 310 |
+
ctx.strokeStyle = color.replace(')', `, ${alpha})`).replace('hsl', 'hsla');
|
| 311 |
+
ctx.lineWidth = this.size * 0.7;
|
| 312 |
+
ctx.lineTo(this.history[i].x, this.history[i].y);
|
| 313 |
+
ctx.stroke();
|
| 314 |
+
ctx.beginPath();
|
| 315 |
+
ctx.moveTo(this.history[i].x, this.history[i].y);
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// Draw particle
|
| 320 |
+
ctx.beginPath();
|
| 321 |
+
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
| 322 |
+
ctx.fillStyle = color;
|
| 323 |
+
ctx.fill();
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
calculateAverageDistance() {
|
| 327 |
+
let totalDist = 0;
|
| 328 |
+
let count = 0;
|
| 329 |
+
|
| 330 |
+
for (let i = 1; i < this.history.length; i++) {
|
| 331 |
+
const dx = this.history[i].x - this.history[i-1].x;
|
| 332 |
+
const dy = this.history[i].y - this.history[i-1].y;
|
| 333 |
+
totalDist += Math.sqrt(dx * dx + dy * dy);
|
| 334 |
+
count++;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
return count > 0 ? totalDist / count : 0;
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// Simulation state
|
| 342 |
+
let particles = [];
|
| 343 |
+
let lastTime = 0;
|
| 344 |
+
let frameCount = 0;
|
| 345 |
+
let fps = 0;
|
| 346 |
+
|
| 347 |
+
function initSimulation() {
|
| 348 |
+
particles = [];
|
| 349 |
+
for (let i = 0; i < params.particleCount; i++) {
|
| 350 |
+
particles.push(new Particle());
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
function resetSimulation() {
|
| 355 |
+
initSimulation();
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
function animate(currentTime) {
|
| 359 |
+
// Calculate FPS
|
| 360 |
+
frameCount++;
|
| 361 |
+
if (currentTime - lastTime >= 1000) {
|
| 362 |
+
fps = frameCount;
|
| 363 |
+
frameCount = 0;
|
| 364 |
+
lastTime = currentTime;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Clear canvas with fade effect
|
| 368 |
+
ctx.fillStyle = `rgba(0, 0, 0, ${params.trailLength})`;
|
| 369 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 370 |
+
|
| 371 |
+
// Update and draw all particles
|
| 372 |
+
for (let particle of particles) {
|
| 373 |
+
particle.update(particles);
|
| 374 |
+
particle.draw(ctx);
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// Draw FPS counter
|
| 378 |
+
ctx.fillStyle = 'white';
|
| 379 |
+
ctx.font = '14px Arial';
|
| 380 |
+
ctx.fillText(`FPS: ${fps}`, 10, 20);
|
| 381 |
+
ctx.fillText(`Particles: ${particles.length}`, 10, 40);
|
| 382 |
+
|
| 383 |
+
requestAnimationFrame(animate);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// Handle window resize
|
| 387 |
+
window.addEventListener('resize', () => {
|
| 388 |
+
canvas.width = window.innerWidth;
|
| 389 |
+
canvas.height = window.innerHeight;
|
| 390 |
+
});
|
| 391 |
+
|
| 392 |
+
// Start simulation
|
| 393 |
+
initSimulation();
|
| 394 |
+
animate();
|
| 395 |
+
});
|
| 396 |
+
</script>
|
| 397 |
+
<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=raayraay/hypnotic-flocking" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
|
| 398 |
+
</html>
|