smoothretro82

(color update) Mouse drawing script 0.2

Dec 22nd, 2025 (edited)
86
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. let keyHeld = false; // Shift key status
  2. let altHeld = false; // Alt key status
  3. let currentColor = 2; // starting color index
  4. const colors = [0, 30, 1, 2, 23, 15, 4, 7, 24, 16, 9, 8, 17, 18, 25, 12, 11, 10, 19, 20, 26, 14, 13, 27, 28, 21, 3, 22, 6, 29]; // adjust as needed
  5.  
  6. // Track Shift and Alt keys
  7. document.addEventListener('keydown', e => {
  8. if (e.key === "Shift") keyHeld = true;
  9. if (e.key === "Alt") altHeld = true;
  10. });
  11. document.addEventListener('keyup', e => {
  12. if (e.key === "Shift") keyHeld = false;
  13. if (e.key === "Alt") altHeld = false;
  14. lastX = null;
  15. lastY = null;
  16. });
  17.  
  18. // Track mouse movement
  19. let mouseX = 0;
  20. let mouseY = 0;
  21. document.addEventListener('mousemove', e => {
  22. mouseX = e.clientX;
  23. mouseY = e.clientY;
  24.  
  25. if (keyHeld) drawAtMouse();
  26. });
  27.  
  28. // Mouse wheel for color cycling
  29. document.addEventListener('wheel', e => {
  30. if (altHeld) {
  31. e.preventDefault(); // prevent page scroll
  32. if (e.deltaY < 0) { // wheel up
  33. currentColor = (currentColor + 1) % colors.length;
  34. } else { // wheel down
  35. currentColor = (currentColor - 1 + colors.length) % colors.length;
  36. }
  37. console.log("Current color:", currentColor);
  38. }
  39. }, { passive: false });
  40.  
  41. // Convert OS mouse position to canvas coordinates and draw
  42. function drawAtMouse() {
  43. const charWidth = 5;
  44. const charHeight = 8;
  45. const rect = document.body.getBoundingClientRect();
  46. const x = Math.floor((mouseX - rect.left) / charWidth);
  47. const y = Math.floor((mouseY - rect.top) / charHeight);
  48.  
  49. if (lastX !== null && lastY !== null) {
  50. const dx = x - lastX;
  51. const dy = y - lastY;
  52. const steps = Math.max(Math.abs(dx), Math.abs(dy));
  53. for (let i = 1; i <= steps; i++) {
  54. const xi = lastX + Math.round(dx * (i / steps));
  55. const yi = lastY + Math.round(dy * (i / steps));
  56. drawCharAtCell(xi, yi);
  57. }
  58. } else {
  59. drawCharAtCell(x, y);
  60. }
  61.  
  62. lastX = x;
  63. lastY = y;
  64. }
  65.  
  66. // Draw a single character at a cell using currentColor
  67. function drawCharAtCell(x, y) {
  68. const format = colFmt(currentColor, { bold: true });
  69. writeCharAt("█", format, x, y);
  70. }
  71.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment