Advertisement
lemansky

Untitled

May 14th, 2025
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Circles</title>
  7.   <style>
  8.     canvas {
  9.       background: black;
  10.     }
  11.   </style>
  12. </head>
  13. <body>
  14.   <canvas id="myCanvas" width="800" height="800"></canvas>
  15.  
  16.   <script>
  17.     const canvas = document.querySelector('canvas');
  18.     const ctx = canvas.getContext("2d");
  19.     ctx.lineWidth = 2;
  20.     ctx.strokeStyle = 'white';  
  21.     canvas.addEventListener('mousemove', (e) => {
  22.       ctx.clearRect(0, 0, canvas.width, canvas.height);
  23.       let mouseX = e.offsetX;
  24.       let mouseY = e.offsetY;
  25.  
  26.       let distanceToCenterX = Math.abs(mouseX - canvas.width / 2);
  27.       let distanceToCenterY = Math.abs(mouseY - canvas.height / 2);
  28.      
  29.       let growingValue = (distanceToCenterX + distanceToCenterY) / 4;
  30.  
  31.       for(let i = 0; i < 5; i++){
  32.        let x = 0;
  33.        if(e.offsetX > canvas.width/2){
  34.           x = i*40 ;
  35.         } else if( e.offsetX < canvas.width/2){
  36.          x = -i*40;
  37.        } else {
  38.          x = 0;
  39.        }
  40.        let y = 0;
  41.        if(e.offsetY > canvas.height/2){
  42.           y = i*40;
  43.         } else if(e.offsetY < canvas.height/2){
  44.          y = -i*40;
  45.        } else {
  46.          y = 0
  47.        }
  48.        console.log(20 + i*growingValue);
  49.        ctx.beginPath();
  50.        ctx.arc(canvas.width/2 + x, canvas.height/2 + y, 20 + i*growingValue, 0, Math.PI*2);
  51.        ctx.closePath();
  52.        ctx.stroke();
  53.      }
  54.    });
  55.  </script>
  56. </body>
  57. </html>
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement