[comp.emacs] Another boring night at the terminal..

jonasf@kuling.UUCP (Jonas Flygare ) (10/08/87)

I got fed up with studying, so I wrote this little program.
Sorry all you people with non-vt100's, but when I get bored again
I am going to look more into the code for hanoi, to make it terminal
independent. Don't flame me if you don't like it. Feel free to improve on it!
Oh, yes, the program really should have the ususal GNU header, since I swiped 
some code out of yow.el. If you don't have GNU emacs (this is v.17.64)
I guess there is some hacking to do. If I ever get to make a mode out of this
(that will be on a **RAINY** day.. :-) I'll post it..
Here goes..

------------------------cut here and put in shaker.el------------------------

;;;Split text string into chars, and put them into a vector along with
;;;info on what position they have.

(defun put-string-in-vector (text)
  (let* ((vector (make-vector (length text) '(0 0 0)))
	 (x-index 0)
	 (y-index 0)
	 (inchar 0)
	 (loop (length text))
	 (index loop)
	 (realpos 0))
    (while (/= 0 loop)
      (setq currpos (- index loop))
      (setq inchar (aref text currpos))
      (cond ((or (char-equal inchar 13)
		 (char-equal inchar 10))
	     (setq loop (1- loop))
	     (setq y-index (1+ y-index))
	     (setq x-index 0))
	    (t (aset vector realpos (list inchar x-index y-index))
	       (setq realpos (1+ realpos))
	       (setq x-index (1+ x-index))
	       (setq loop (1- loop)))))
    (while (<= loop (1- realpos))
      (swap loop (myrand (1- realpos)) vector)
      (setq loop (1+ loop)))
    vector))

;;; Need some kind of random function. No flames please, i was tired!
(defun myrand (maxval)
  (let ((inval (random)))
	(if (< inval 0)
	    (setq inval (- 0 inval)))
	(- inval (* maxval (/ inval maxval)))))


;;; swap two elements in a vector
(defun swap (pos1 pos2 vector)
  (let ((tem1 (aref vector pos1))
	(tem2 (aref vector pos2)))
    (aset vector pos2 tem1)
    (aset vector pos1 tem2)))


;;; This is the main function. It really should be rewritten so it makes a
;;; new buffer and puts the characters into it, ala hanoi. Well,
;;; I'll do it any day... As for now, VT100 ONLY..
(defun display-hack (lista)
  (send-string-to-terminal "7")
  (let* ((loop 0)
	 (stop (length lista))
	 (element '(666 4711 11147)))
    (while (and (/= (car element) 0)
		    (/= loop stop))
    (setq element (aref lista loop))
    (send-string-to-terminal (concat "[" 
				     (int-to-string
				      (+ (car (cdr (cdr element))) 24))
				     ";"
				     (int-to-string
				      (1+ (car (cdr element))) )
				     "H"))
    (send-string-to-terminal (char-to-string (car element)))
    (setq loop (1+ loop)))
    (sit-for 3)
    (send-string-to-terminal "[24;0H")
    (send-string-to-terminal "                                                                               ")
    (send-string-to-terminal "8")))

(load "yow.el")
;;;Need this for cookies to feed the monster.

;;;Cookie monster, gobbling all there is in the can... ;-)
;;; Most of this came from yow.el
(defun random-yow ()
  (if (null yow-vector)
      (setq yow-vector (snarf-yows)))
  (let ((yow (aref yow-vector
		     (% (logand 0777777 (random)) (length yow-vector)))))
    (display-hack (put-string-in-vector yow))))

;;;Now show what it really is about. Neat, isn't it.
;;;Not blindingly fast, but hey, you can always rewrite it in C...
(random-yow)
(sit-for 1)
(random-yow)
(sit-for 1)