Advertisement
lemansky

Untitled

Dec 4th, 2020 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7.  
  8.     <script>
  9.         document.addEventListener("DOMContentLoaded", () => {
  10.             let canvas = document.getElementById("canvasId");
  11.             let context = canvas.getContext("2d");
  12.             let mouse;
  13.  
  14.             const points = () =>{
  15.                 context.beginPath();
  16.                 context.moveTo(150, 50);
  17.                 context.lineTo(225, 200);
  18.                 context.lineTo(75, 100);
  19.                 context.lineTo(225, 100);
  20.                 context.lineTo(75, 200);
  21.                 context.lineTo(150, 50);
  22.                 context.closePath();
  23.             }
  24.  
  25.             context.strokeStyle = "white";
  26.             points();
  27.             context.stroke();
  28.  
  29.             document.addEventListener("click", (e) => {
  30.                 mouse = mousePlayer1(e);
  31.  
  32.                 points();
  33.                 if(context.isPointInPath(mouse.x, mouse.y)){
  34.                     alert("yes");
  35.                 } else {
  36.                     alert("no");
  37.                 }
  38.             });
  39.         });
  40.  
  41.         const mousePlayer1 = (e) => {
  42.             return {
  43.                 x: e.layerX,
  44.                 y: e.layerY,
  45.             }
  46.         }
  47.  
  48.  
  49.         </script>
  50.     <style type="text/css">
  51.     #canvasId{
  52.         background: black;
  53.     }
  54.     </style>
  55. </head>
  56.     <body>
  57.         <canvas id="canvasId" width="700" height="600"></canvas>
  58.     </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement