1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
   | <!DOCTYPE html> <html lang="en">     <head>         <meta charset="UTF-8" />         <meta http-equiv="X-UA-Compatible" content="IE=edge" />         <meta name="viewport" content="width=device-width, initial-scale=1.0" />         <title>Document</title>     </head>     <body>         <canvas id="container" style="border: 1px solid"></canvas>         <script src="./EllipsisGenerator.js"></script>         <script>             const bubbleCount = 100;              const bubbleRadius = 10;              const frameRate = 40;              const bubbleColor = 'yellowgreen';             const bubbles = [];             class Bubble {                 x;                 y;                 r;                 alpha;                 constructor(x = 0, y = 0, r = 1, alpha = 1) {                     this.x = x;                     this.y = y;                     this.r = r;                     this.alpha = alpha;                 }             }
              const $star = document.getElementById('container');             const width = 600;             const height = 400;             $star.width = width;             $star.height = height;
              const elliptic = new EllipsisGenerator(                 width / 2,                 height / 2,                 width / 2 - bubbleRadius,                 height / 2 - bubbleRadius,                 0,                 -1             );             const generate = elliptic.generate();
              const ctx = $star.getContext('2d');
              const run = () => {                 ctx.clearRect(0, 0, width, height);                 let { x, y } = generate.next().value;
                  if (bubbles.length >= bubbleCount) {                     bubbles.shift();                 }
                  let bubble = new Bubble(x, y, 2);                 bubbles.push(bubble);
                                   for (let i = 0; i < bubbles.length; i++) {                     let bubble = bubbles[i];                     bubble.alpha = (i + 1) * (1 / bubbleCount);                     bubble.r = bubble.r * (i + 1) * (1 / bubbleCount);
                      ctx.save();                     ctx.beginPath();                     ctx.globalAlpha = bubble.alpha * 0.5;                     ctx.fillStyle = bubbleColor;                     ctx.arc(                         bubble.x,                         bubble.y,                         bubble.r * 4,                         0,                         2 * Math.PI,                         false                     );                     ctx.fill();                     ctx.restore();                 }
                  setTimeout(() => {                     requestAnimationFrame(run);                 }, 1000 / frameRate);             };
              run();         </script>     </body> </html>
 
   |