Skip to content

Instantly share code, notes, and snippets.

@clemera
Created December 11, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemera/a4d235a1d5194fe63e21 to your computer and use it in GitHub Desktop.
Save clemera/a4d235a1d5194fe63e21 to your computer and use it in GitHub Desktop.
Small Emacs ASCII animation
;;(require 'drawille)
(load-file "drawille.el")
(defvar aa-pixel 1
"A one in the matrix represents a set pixel")
(defun aa-matrix-set (matrix col row elt)
"Helper to set values in the matrix"
(let ((grid-row (aref matrix row)))
(aset grid-row col elt)))
(defun aa-create-circle (matrix start end stepsize radius &optional xshift yshift)
(dolist (x (number-sequence start end stepsize))
(aa-matrix-set matrix
(floor (+ radius (or xshift 0) (* radius (cos (radians-to-degrees x)))))
(floor (+ radius (or yshift 0) (* radius (sin (radians-to-degrees x)))))
aa-pixel)))
(defun aa-get-circle-frames (anim-length)
"Creating the animation frames"
(interactive)
(let* ((i 1)
(dr 1)
(radius 2)
matrix
frames)
(while (<= i anim-length)
(setq radius (+ dr radius))
;; (+ radius (* radius cos/sin...))
(setq vheight (* 2 radius))
(setq vwidth (* 2 radius))
(message "Creating frame %s of %s" i anim-length)
;; reinitialize an empty matrix
(setq matrix
(let ((grid (make-vector vheight nil)))
(dotimes (row vheight)
(aset grid row (make-vector vwidth 0)))
grid))
(aa-create-circle matrix 2 360 8 radius)
(aa-create-circle matrix 16 360 8 (- radius 1) 1 1)
(aa-create-circle matrix 32 360 8 (- radius 2) 2 2)
(add-to-list 'frames (drawille-matrix matrix) t)
(setq i (1+ i)))
frames))
(defun aa-init-draw-buffer ()
"Initialize the drawing buffer"
(buffer-disable-undo)
(setq cursor-type nil))
(defun aa-animate-circle (anim-length)
"Start the animation"
(let (frames)
(setq frames (aa-get-circle-frames anim-length))
(switch-to-buffer (get-buffer-create "*draw*"))
(while t
(dolist (frame frames)
(aa-init-draw-buffer)
(erase-buffer)
(insert frame)
(put-text-property (point-min) (point-max) 'face '(foreground-color . "#8a2be2"))
(sit-for 0.1)))))
(aa-animate-circle 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment