Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let keyHeld = false; // Shift key status
- let altHeld = false; // Alt key status
- let currentColor = 2; // starting color index
- 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
- // Track Shift and Alt keys
- document.addEventListener('keydown', e => {
- if (e.key === "Shift") keyHeld = true;
- if (e.key === "Alt") altHeld = true;
- });
- document.addEventListener('keyup', e => {
- if (e.key === "Shift") keyHeld = false;
- if (e.key === "Alt") altHeld = false;
- lastX = null;
- lastY = null;
- });
- // Track mouse movement
- let mouseX = 0;
- let mouseY = 0;
- document.addEventListener('mousemove', e => {
- mouseX = e.clientX;
- mouseY = e.clientY;
- if (keyHeld) drawAtMouse();
- });
- // Mouse wheel for color cycling
- document.addEventListener('wheel', e => {
- if (altHeld) {
- e.preventDefault(); // prevent page scroll
- if (e.deltaY < 0) { // wheel up
- currentColor = (currentColor + 1) % colors.length;
- } else { // wheel down
- currentColor = (currentColor - 1 + colors.length) % colors.length;
- }
- console.log("Current color:", currentColor);
- }
- }, { passive: false });
- // Convert OS mouse position to canvas coordinates and draw
- function drawAtMouse() {
- const charWidth = 5;
- const charHeight = 8;
- const rect = document.body.getBoundingClientRect();
- const x = Math.floor((mouseX - rect.left) / charWidth);
- const y = Math.floor((mouseY - rect.top) / charHeight);
- if (lastX !== null && lastY !== null) {
- const dx = x - lastX;
- const dy = y - lastY;
- const steps = Math.max(Math.abs(dx), Math.abs(dy));
- for (let i = 1; i <= steps; i++) {
- const xi = lastX + Math.round(dx * (i / steps));
- const yi = lastY + Math.round(dy * (i / steps));
- drawCharAtCell(xi, yi);
- }
- } else {
- drawCharAtCell(x, y);
- }
- lastX = x;
- lastY = y;
- }
- // Draw a single character at a cell using currentColor
- function drawCharAtCell(x, y) {
- const format = colFmt(currentColor, { bold: true });
- writeCharAt("█", format, x, y);
- }
Advertisement
Comments
-
- hold shift and move your mouse to draw nearby. run it from eruda
Add Comment
Please, Sign In to add comment