Monorepo for Aesthetic.Computer aesthetic.computer
at main 41 lines 3.7 kB view raw
1 2 ;; Define the XPM image as a string 3 (setq my-xpm-image "\ 4 /* XPM */ 5 static char * example_xpm[] = { 6 \"4 4 2 1\", 7 \" c None\", 8 \"X c #000000\", 9 \" \", 10 \" XX \", 11 \" XX \", 12 \" \"}; 13 ") 14 15 ;; Insert the XPM image string into the scratch buffer 16 (with-current-buffer "*scratch*" 17 (insert my-xpm-image) 18 (image-mode)) ;; Switch to image mode to view the image 19 20 (defun update-xpm-image (x y color) 21 "Update the XPM image at position X Y with COLOR." 22 (let ((image-lines (split-string my-xpm-image "\n"))) 23 ;; Calculate the line number based on the XPM header size 24 (let ((line-number (+ y 4))) ;; Adjust 4 for the XPM header size 25 ;; Replace the character at the specified position 26 (let ((line (nth line-number image-lines))) 27 (when line 28 (let ((new-line (concat (substring line 0 x) 29 color 30 (substring line (1+ x))))) 31 (setf (nth line-number image-lines) new-line) 32 ;; Update the image string 33 (setq my-xpm-image (string-join image-lines "\n")) 34 ;; Update the buffer content 35 (with-current-buffer "*scratch*" 36 (erase-buffer) 37 (insert my-xpm-image) 38 (image-mode))))))) 39 40 ;; Example usage: Set the pixel at (1, 1) to black 41 (update-xpm-image 1 1 "X")