Dan Torop

Part 2: minimal ASCII art

Continued from Emacs Lisp programming pt. 1.

Using random

ELISP> (dotimes (i (random 10))
	 (dotimes (j (random (+ i 5)))
	   (insert "&"))
	 (insert "^"))
nil
ELISP> &&^&&&&^&&&&^&&&&^&&&&&&&&^&&&&&&&^

Using if to sometimes insert newlines

ELISP> (dotimes (i (random 30))
	 (if (= (random 5) 0)
	     (newline))
	 (dotimes (j (random 10))
	   (insert "?"))
	 (insert " <  "))
nil
ELISP> ?? <  
?? <  ?? <   <  ?? <  ????? <  
???????? <  ?????? <  
 <  ??????? <  
????????? <  ???????? <  ??????? <  
 <  ???????? <  ?? <  ???????? <  ???? <  ????????? <  ???????? <  ??? <  ????????? <  ?? <  ????? <  ??? <  
??? <  ????????? <  

Using sit-for to control time

ELISP> (dotimes (i 10)
	 (dotimes (j (random 20))
	   (insert ",,"))
	 (insert "#")
	 (sit-for (* 0.1 (random 4))))
nil
ELISP> ,,,,,,,,,,#,,,,##,,,,,,,,#,,,,,,,,,,,,#,,,,,,,,,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,#,,,,,,,,,,,,,,#

Moving cursor while inserting

ELISP> (dotimes (i 20)
	 (dotimes (j (random 5))
	   (insert ",,"))
	 (goto-char (- (point) (random 4)))
	 (insert "#")
	 (if (= (random 3) 0)
	     (newline))
	 (sit-for (* 0.1 (random 3))))#
,,,,,,,,#
,,,,,#
,,,,,,#,,##,,,#,,#
,,,,#,,,#,,,,,,#,,,#,#
,,,#,,,#,,,,,,,,,,,#
#,,#,,,#,,,,,,,,#,,,,,
nil
ELISP> 

A slightly easier way to do the same

ELISP> (dotimes (i 20)
	 (dotimes (j (random 5))
	   (insert ",,"))
	 (backward-char (random 4))
	 (insert "#")
	 (if (= (random 3) 0)
	     (newline))
	 (sit-for (* 0.1 (random 3))))
nil
ELISP> ,,##,,,#
#,,,,,,,,##
,,#,,,,,,#,#,,,,,##,#,#,,,#,,,,,,#
#
,,#,,,,,,,,,
,,,#,#,,,,,,,,,,,
,#,

Continued in Emacs Lisp programming pt. 3.