Skip to content

Commit

Permalink
feat(fun): snowcrash simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
winny- committed Nov 10, 2024
1 parent 319d9a7 commit 783f8a9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.webm filter=lfs diff=lfs merge=lfs -text
13 changes: 13 additions & 0 deletions configuration.org
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,19 @@ Enable =narrow-to-region=
(put 'narrow-to-region 'disabled nil)
#+END_SRC

* For the fun of it

** Snowcrash

White noise for the whole family.

[[file:misc/snowcrash.webm]]

#+begin_src emacs-lisp
(use-package snowcrash
:demand t)
#+end_src

* Emacs daemon/server quick keys
Like =with-editor=, set up =server.el= (see =server-visit-files=) with =C-c
C-c= to "commit" save and close the buffer, and =C-c C-k= to revert and close
Expand Down
3 changes: 3 additions & 0 deletions misc/snowcrash.webm
Git LFS file not shown
49 changes: 49 additions & 0 deletions site-lisp/snowcrash.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(defvar snowcrash--refresh-rate "1 sec")

(defvar snowcrash--symbols '(?█ ? ))
;; (defvar snowcrash--symbols '(?. ? ))

(defvar snowcrash--buffer-name "*snowcrash*")

(defvar snowcrash--timer nil)

(defun snowcrash--draw ()
"Draw snowcrash in the current buffer."
(with-current-buffer (get-buffer snowcrash--buffer-name)
(read-only-mode -1)
(erase-buffer)
(dotimes (lines (1- (window-total-height nil 'floor)))
(dotimes (columns (1- (window-total-width nil 'floor)))
(insert-char (nth (random (length snowcrash--symbols))
snowcrash--symbols)))
(unless (= lines (- (window-total-height nil t) 2))
(newline)))
(goto-char (point-min))
(read-only-mode 1)))

(defun snowcrash--tick ()
(snowcrash--draw)
(setq snowcrash--timer
(run-with-timer snowcrash--refresh-rate t #'snowcrash--tick)))

(defun snowcrash ()
(interactive)
(switch-to-buffer (get-buffer-create snowcrash--buffer-name))
(snowcrash-mode))

(defun snowcrash--quit-window-hook ()
(when (and (eq major-mode 'snowcrash-mode)
snowcrash--timer)
(cancel-timer snowcrash--timer)
(setq snowcrash--timer nil)))

(define-derived-mode
snowcrash-mode
special-mode
"Snowcrash"
"Draw snowcrash noise. Fun for the entire family!"
(add-hook 'quit-window-hook #'snowcrash--quit-window-hook)
(message "Type q to quit.")
(snowcrash--tick))

(provide 'snowcrash)

0 comments on commit 783f8a9

Please sign in to comment.