Advertisement
xpppppppaicyber

xc8ballpool

Sep 26th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 8 Ball Pool Line Calculator with Precise Hole Locations (Console Script)
  2.  
  3. (function() {
  4.     let isDrawing = false;
  5.     let svg;
  6.     let holes = [
  7.         {x: 455, y: 300},  // Top-left
  8.         {x: 792, y: 300},  // Top-middle
  9.         {x: 1135, y: 300}, // Top-right
  10.         {x: 451, y: 656},  // Bottom-left
  11.         {x: 794, y: 656},  // Bottom-middle
  12.         {x: 1133, y: 656}  // Bottom-right
  13.     ];
  14.     let draggedHole = null;
  15.     let cueBall = {x: 792, y: 478}; // Initial cue ball position (center of the table)
  16.  
  17.     function createToggleButton() {
  18.         const button = document.createElement('button');
  19.         button.textContent = 'Toggle Lines';
  20.         button.style.cssText = `
  21.             position: fixed;
  22.             top: 10px;
  23.             right: 10px;
  24.             z-index: 9999;
  25.             padding: 10px;
  26.             background-color: #4CAF50;
  27.             color: white;
  28.             border: none;
  29.             cursor: pointer;
  30.             font-size: 16px;
  31.         `;
  32.         button.addEventListener('click', toggleDrawing);
  33.         document.body.appendChild(button);
  34.     }
  35.  
  36.     function toggleDrawing() {
  37.         isDrawing = !isDrawing;
  38.         if (isDrawing) {
  39.             calculateAndDrawLines();
  40.         } else {
  41.             removeLines();
  42.         }
  43.     }
  44.  
  45.     function calculateAndDrawLines() {
  46.         removeLines(); // Clear existing lines
  47.  
  48.         svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  49.         svg.setAttribute("width", "100%");
  50.         svg.setAttribute("height", "100%");
  51.         svg.style.cssText = `
  52.             position: absolute;
  53.             top: 0;
  54.             left: 0;
  55.             pointer-events: none;
  56.             z-index: 9998;
  57.         `;
  58.  
  59.         holes.forEach((hole, index) => {
  60.             // Draw line
  61.             const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
  62.             line.setAttribute("x1", cueBall.x);
  63.             line.setAttribute("y1", cueBall.y);
  64.             line.setAttribute("x2", hole.x);
  65.             line.setAttribute("y2", hole.y);
  66.             line.setAttribute("stroke", "red");
  67.             line.setAttribute("stroke-width", "2");
  68.             svg.appendChild(line);
  69.  
  70.             // Draw hole
  71.             const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
  72.             circle.setAttribute("cx", hole.x);
  73.             circle.setAttribute("cy", hole.y);
  74.             circle.setAttribute("r", "10");
  75.             circle.setAttribute("fill", "blue");
  76.             circle.style.pointerEvents = "none";
  77.             svg.appendChild(circle);
  78.  
  79.             // Display coordinates
  80.             const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
  81.             text.setAttribute("x", hole.x);
  82.             text.setAttribute("y", hole.y - 15); // Position above the circle
  83.             text.setAttribute("text-anchor", "middle");
  84.             text.setAttribute("fill", "black");
  85.             text.setAttribute("font-size", "12px");
  86.             text.textContent = `(${Math.round(hole.x)}, ${Math.round(hole.y)})`;
  87.             text.style.pointerEvents = "none";
  88.             svg.appendChild(text);
  89.         });
  90.  
  91.         // Draw draggable cue ball
  92.         const cueBallCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
  93.         cueBallCircle.setAttribute("cx", cueBall.x);
  94.         cueBallCircle.setAttribute("cy", cueBall.y);
  95.         cueBallCircle.setAttribute("r", "10");
  96.         cueBallCircle.setAttribute("fill", "white");
  97.         cueBallCircle.setAttribute("stroke", "black");
  98.         cueBallCircle.style.cursor = "move";
  99.         cueBallCircle.style.pointerEvents = "all";
  100.         cueBallCircle.addEventListener('mousedown', startDraggingCueBall);
  101.         svg.appendChild(cueBallCircle);
  102.  
  103.         // Display cue ball coordinates
  104.         const cueBallText = document.createElementNS("http://www.w3.org/2000/svg", "text");
  105.         cueBallText.setAttribute("x", cueBall.x);
  106.         cueBallText.setAttribute("y", cueBall.y - 15);
  107.         cueBallText.setAttribute("text-anchor", "middle");
  108.         cueBallText.setAttribute("fill", "black");
  109.         cueBallText.setAttribute("font-size", "12px");
  110.         cueBallText.textContent = `(${Math.round(cueBall.x)}, ${Math.round(cueBall.y)})`;
  111.         cueBallText.style.pointerEvents = "none";
  112.         svg.appendChild(cueBallText);
  113.  
  114.         document.body.appendChild(svg);
  115.         document.addEventListener('mousemove', dragCueBall);
  116.         document.addEventListener('mouseup', stopDragging);
  117.     }
  118.  
  119.     function startDraggingCueBall(e) {
  120.         draggedHole = e.target;
  121.     }
  122.  
  123.     function dragCueBall(e) {
  124.         if (draggedHole) {
  125.             e.preventDefault();
  126.             cueBall = { x: e.clientX, y: e.clientY };
  127.             calculateAndDrawLines();
  128.         }
  129.     }
  130.  
  131.     function stopDragging() {
  132.         draggedHole = null;
  133.     }
  134.  
  135.     function removeLines() {
  136.         if (svg && svg.parentNode) {
  137.             svg.parentNode.removeChild(svg);
  138.         }
  139.         document.removeEventListener('mousemove', dragCueBall);
  140.         document.removeEventListener('mouseup', stopDragging);
  141.     }
  142.  
  143.     // Initialize
  144.     createToggleButton();
  145.     console.log("8 Ball Pool Line Calculator initialized with precise hole locations. Click the 'Toggle Lines' button to show/hide lines. You can drag the white circle to reposition the cue ball. Coordinates are displayed above each hole and the cue ball.");
  146. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement