Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const canvas = document.getElementById('goopCanvas');
+ const ctx = canvas.getContext('2d');
+ const colorBtn = document.getElementById('colorBtn');
+ const viscosityBtn = document.getElementById('viscosityBtn');
+ const resetBtn = document.getElementById('resetBtn');
+
+ // Set canvas size
+ function resizeCanvas() {
+ const container = canvas.parentElement;
+ canvas.width = container.clientWidth;
+ canvas.height = container.clientHeight;
+ }
+
+ window.addEventListener('resize', resizeCanvas);
+ resizeCanvas();
+
+ // Goop simulation parameters
+ let goop = {
+ particles: [],
+ color: getComputedStyle(document.documentElement).getPropertyValue('--goop-color'),
+ viscosity: 0.95,
+ particleCount: 150,
+ maxSize: 30,
+ minSize: 10
+ };
+
+ // Initialize particles
+ function initParticles() {
+ goop.particles = [];
+ for (let i = 0; i < goop.particleCount; i++) {
+ goop.particles.push({
+ x: Math.random() * canvas.width,
+ y: Math.random() * canvas.height,
+ vx: Math.random() * 4 - 2,
+ vy: Math.random() * 4 - 2,
+ size: Math.random() * (goop.maxSize - goop.minSize) + goop.minSize,
+ color: goop.color
+ });
+ }
+ }
+
+ // Update and draw particles
+ function updateParticles() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ for (let i = 0; i < goop.particles.length; i++) {
+ const p = goop.particles[i];
+
+ // Update position with viscosity
+ p.x += p.vx;
+ p.y += p.vy;
+
+ // Bounce off walls
+ if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
+ if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
+
+ // Apply viscosity
+ p.vx *= goop.viscosity;
+ p.vy *= goop.viscosity;
+
+ // Draw particle
+ ctx.beginPath();
+ ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
+ ctx.fillStyle = p.color;
+ ctx.fill();
+
+ // Draw connections to nearby particles
+ for (let j = i + 1; j < goop.particles.length; j++) {
+ const p2 = goop.particles[j];
+ const dx = p.x - p2.x;
+ const dy = p.y - p2.y;
+ const distance = Math.sqrt(dx * dx + dy * dy);
+
+ if (distance < 100) {
+ ctx.beginPath();
+ ctx.moveTo(p.x, p.y);
+ ctx.lineTo(p2.x, p2.y);
+ ctx.strokeStyle = `${p.color}${Math.floor((1 - distance/100) * 50 + 50).toString(16).padStart(2, '0')}`;
+ ctx.lineWidth = 1;
+ ctx.stroke();
+ }
+ }
+ }
+
+ requestAnimationFrame(updateParticles);
+ }
+
+ // Button event handlers
+ colorBtn.addEventListener('click', () => {
+ const hue = Math.floor(Math.random() * 360);
+ goop.color = `hsl(${hue}, 70%, 60%)`;
+ goop.particles.forEach(p => {
+ p.color = goop.color;
+ });
+ });
+
+ viscosityBtn.addEventListener('click', () => {
+ goop.viscosity = Math.random() * 0.2 + 0.8;
+ });
+
+ resetBtn.addEventListener('click', () => {
+ initParticles();
+ goop.viscosity = 0.95;
+ goop.color = getComputedStyle(document.documentElement).getPropertyValue('--goop-color');
+ });
+
+ // Mouse interaction
+ canvas.addEventListener('mousemove', (e) => {
+ const rect = canvas.getBoundingClientRect();
+ const mouseX = e.clientX - rect.left;
+ const mouseY = e.clientY - rect.top;
+
+ goop.particles.forEach(p => {
+ const dx = mouseX - p.x;
+ const dy = mouseY - p.y;
+ const distance = Math.sqrt(dx * dx + dy * dy);
+
+ if (distance < 150) {
+ const force = 150 / distance;
+ p.vx += dx * 0.0005 * force;
+ p.vy += dy * 0.0005 * force;
+ }
+ });
+ });
+
+ // Touch interaction
+ canvas.addEventListener('touchmove', (e) => {
+ e.preventDefault();
+ const rect = canvas.getBoundingClientRect();
+ const touch = e.touches[0];
+ const touchX = touch.clientX - rect.left;
+ const touchY = touch.clientY - rect.top;
+
+ goop.particles.forEach(p => {
+ const dx = touchX - p.x;
+ const dy = touchY - p.y;
+ const distance = Math.sqrt(dx * dx + dy * dy);
+
+ if (distance < 150) {
+ const force = 150 / distance;
+ p.vx += dx * 0.0005 * force;
+ p.vy += dy * 0.0005 * force;
+ }
+ });
+ }, { passive: false });
+
+ // Initialize and start animation
+ initParticles();
+ updateParticles();
+ });