I think need to implement a declaration of visible orbit lines or dots or not in canvas…
- User
I think need to implement a declaration of visible orbit lines or dots or not in canvas (like 1 or 0), to leave only orbits or dots visible. output fully integrated code only: const canvas = document.createElement('canvas'); document.body.appendChild(canvas);
const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight;
const numOrbits = 10; const dotsPerOrbit = 80; const maxOrbitRadius = Math.min(canvas.width, canvas.height) / 2; const orbitInterchangeProbability = 0.8; const orbitTransitionSpeed = 0.5; const dotInterchangeProbability = 0.01; const dotInterchangeSpeed = 0.01; const dotExchangeDirection = 'linear'; // Can be 'linear' or 'random'
let orbits = [];
function getDotColors() { let dotColors = []; for (let i = 0; i < dotsPerOrbit; i++) { const hue = 360 * (i / dotsPerOrbit); dotColors.push('hsl(' + hue + ', 100%, 50%)'); } return dotColors; }
for (let i = 0; i < numOrbits; i++) { let distance = maxOrbitRadius * (i + 1) / numOrbits; let rotationSpeed = 0.005 + Math.random() * 0.005; let rotationDirection = Math.random() < 0.5 ? 1 : -1; let color = 'hsl(' + (i * 360 / numOrbits) + ', 100%, 50%)'; let dotColors = getDotColors(); let dots = []; for (let j = 0; j < dotsPerOrbit; j++) { let angle = (j / dotsPerOrbit) * Math.PI * 2; dots.push({ currentAngle: angle, targetAngle: angle, currentRadius: distance, targetRadius: distance, color: dotColors[j], orbitIndex: i // Each dot knows which orbit it belongs to }); } orbits.push({ dots: dots, currentRadius: distance, targetRadius: distance, color: color, rotationSpeed: rotationSpeed, rotationDirection: rotationDirection }); }
function drawDot(dot, orbit, centerX, centerY) { const x = centerX + dot.currentRadius * Math.cos(dot.currentAngle); const y = centerY + dot.currentRadius * Math.sin(dot.currentAngle); ctx.fillStyle = dot.color; ctx.beginPath(); ctx.arc(x, y, 3, 0, Math.PI * 2, false); ctx.fill(); }
function drawOrbit(orbit, centerX, centerY) { // Draw orbit path ctx.beginPath(); ctx.arc(centerX, centerY, orbit.currentRadius, 0, Math.PI * 2, false); ctx.strokeStyle = orbit.color; ctx.stroke();
codeorbit.dots.forEach(dot => { drawDot(dot, orbit, centerX, centerY); });}
function updateOrbit(orbit) { // Update the orbit's current radius towards its target for a smooth transition. let radiusDifference = orbit.targetRadius - orbit.currentRadius; orbit.currentRadius += radiusDifference * orbitTransitionSpeed;
code - Assistant
To implement an option to toggle visibility of orbit lines and dots separately with a simple configuration (like setting
1for visible or0for not visible), you can add two variables at the beginning of the script:Let's call these variables
showOrbitLinesandshowDots, and set both to1initially for visibility:javascriptconst showOrbitLines = 1; // Set to 0 to hide orbit lines const showDots = 1; // Set to 0 to hide dotsNext, we'll modify the
drawOrbitanddrawDotfunctions to check the variable before drawing:javascript