Perfect Circle Drawer

Draws a perfect circle

  1. // ==UserScript==
  2. // @name Perfect Circle Drawer
  3. // @namespace example.com
  4. // @version 1.0
  5. // @description Draws a perfect circle
  6. // @author You
  7. // @match *://*/* # Change this to match the desired website
  8. // @grant GM_addStyle
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function drawCircle(x, y, radius, color) {
  13. // Get the canvas element or create one dynamically
  14. let canvas = document.getElementById('myCanvas');
  15. if (!canvas) {
  16. canvas = document.createElement('canvas');
  17. canvas.id = 'myCanvas';
  18. canvas.width = 400; // Adjust as needed
  19. canvas.height = 400; // Adjust as needed
  20. document.body.appendChild(canvas); // Add to the page
  21. }
  22.  
  23. let ctx = canvas.getContext('2d');
  24.  
  25. ctx.beginPath();
  26. ctx.arc(x, y, radius, 0, 2 * Math.PI);
  27. ctx.fillStyle = color;
  28. ctx.fill();
  29. }
  30.  
  31. // Add a button or use a keyboard shortcut
  32. const button = document.createElement('button');
  33. button.textContent = 'Draw Circle';
  34. button.addEventListener('click', function() {
  35. // Example: Draw a circle at (100, 100) with radius 50 and red color
  36. drawCircle(100, 100, 50, 'red');
  37. });
  38.  
  39. document.body.appendChild(button);