Created
February 12, 2012 09:22
-
-
Save Johniel/1807464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq text nil) | |
(setq buff-name "k7script") | |
(setq timer nil) | |
(setq font nil) | |
(setq adj nil) | |
(load-file "path/to/file") | |
(defun k7:rand-walk (pos) | |
(let (neighbor) | |
(setq neighbor (nth pos adj)) | |
(nth (random (length neighbor)) neighbor))) | |
(defun k7:make-line (line) | |
(let (ret) | |
(setq ret "") | |
(while (car line) | |
(setq ret (concat ret (apply 'concat (mapcar 'car line)) "\n")) | |
(setq line (mapcar 'cdr line))) | |
ret)) | |
(defun k7:connect-lines (lines) | |
(let (ret) | |
(map nil '(lambda (line) | |
(setq ret (concat ret (k7:make-line line)))) | |
lines) | |
ret)) | |
(defun k7:update () | |
(setq text (mapcar '(lambda (line) | |
(mapcar '(lambda (c) | |
(list (first c) | |
(k7:rand-walk (car (last c))))) | |
line)) | |
text))) | |
(defun k7:make-chars () | |
(mapcar '(lambda (line) | |
(mapcar '(lambda (c) | |
(split-string (nth (car (last c)) (nth (first c) font)) "\n")) | |
line)) | |
text)) | |
(defun k7:make-script () | |
(k7:update) | |
(insert (format "%s" (k7:connect-lines (k7:make-chars)))) | |
(create-pbm-from-hex (point-min) (point-max))) | |
;; http://ynomura.dip.jp/archives/2010/12/emacs_1.html | |
;; http://ynomura.dip.jp/archives/misc/doteditor.el | |
(defun create-pbm-from-hex (start end) | |
"inserts PBM image data of hexified bitmap into the top of temporal buffer" | |
;; (interactive "r") | |
;; (when mark-active | |
(let ((pbm "") (width 0) (height 0)) | |
(while (< start end) | |
(let (ch1 ch2 n1 n2) ;n: decimal value of a hex char | |
(setq ch1 (char-after start)) ;ch1: hex char for first 4bit | |
(setq ch2 (or (char-after (+ start 1)) ?\0)) ;char-after eob is nil | |
(setq n1 (string-to-number (char-to-string ch1) 16)) | |
(cond ((or (> n1 0) (= ch1 ?0)) ;[1-9a-fA-F] or '0' | |
(setq n2 (string-to-number (char-to-string ch2) 16)) | |
(when (or (> n2 0) (= ch2 ?0)) | |
(setq start (+ 1 start))) | |
(setq pbm (concat pbm (format "%c" (logior (lsh n1 4) n2))))) | |
((= ch1 ?\n) | |
(if (= ch2 ?\n) nil (setq height (+ 1 height))) | |
)) | |
(setq start (+ 1 start)) | |
)) | |
(setq width (* 8 (/ (length pbm) height))) | |
;; (switch-to-buffer "tmp.pbm") | |
(goto-char 1) | |
(insert (format "P4 %d %d " width height) pbm)) | |
(if (functionp 'image-mode) (image-mode) nil) | |
);;) | |
(defun k7:start () | |
(interactive) | |
(let (lines max-len) | |
(setq text '()) | |
(setq lines (split-string (buffer-string) "\n")) | |
(setq max-len (apply 'max (mapcar 'length lines))) | |
(setq lines (mapcar '(lambda (line) | |
(while (< (length line) max-len) | |
(setq line (concat line " "))) | |
line) | |
lines)) | |
(setq text (mapcar '(lambda (line) | |
(mapcar '(lambda (c) | |
(list c 0)) | |
line)) | |
lines)) | |
(setq timer (run-with-timer 1 0.2 '(lambda () | |
(if (buffer-live-p (get-buffer buff-name)) | |
(kill-buffer buff-name)) | |
(switch-to-buffer buff-name) | |
(k7:make-script)))))) | |
;; (defun k7:stop () | |
;; (interactive) | |
;; (cancel-timer timer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment