HTMLify

Loder 2
Views: 38 | Author: djdj
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Lissajous Curve Animation</title>
  <style>
    body {
      margin: 0;
      background-color: black;
    }
    canvas {
      display: block;
    }
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    const canvas = document.getElementById("canvas");
    const ctx = canvas.getContext("2d");

    let width = canvas.width = window.innerWidth;
    let height = canvas.height = window.innerHeight;

    function drawLissajous(time) {
      ctx.clearRect(0, 0, width, height);

      ctx.beginPath();
      ctx.strokeStyle = 'rgba(0, 153, 255, 0.8)';
      ctx.shadowColor = '#00f0ff';
      ctx.shadowBlur = 25;
      ctx.lineWidth = 2;

      const a = 5; // x frequency
      const b = 4; // y frequency
      const delta = Math.PI / 2;
      const scale = 150;
      const centerX = width / 2;
      const centerY = height / 2;

      for (let t = 0; t <= 2 * Math.PI; t += 0.01) {
        const x = centerX + scale * Math.sin(a * t + time / 1000);
        const y = centerY + scale * Math.sin(b * t);

        if (t === 0) {
          ctx.moveTo(x, y);
        } else {
          ctx.lineTo(x, y);
        }
      }

      ctx.stroke();
      requestAnimationFrame(drawLissajous);
    }

    drawLissajous(0);
  </script>
</body>
</html>

Comments