1. (defconstant MAX_ITERATIONS 27)
    
  2. (defconstant OUTPUT_RES_X 3.5)
    
  3. (defconstant OUTPUT_RES_Y 2)
    
  4. (defconstant OUTPUT_OFFSET_X -2.5)
    
  5. (defconstant OUTPUT_OFFSET_Y -1)
    
  6. (defconstant RESOLUTION_X 150)
    
  7. (defconstant RESOLUTION_Y 60)
    
  8. 
    
  9. 
    
  10. ; turn # interations into a char for display
    
  11. (defun show (val) 
    
  12.     (if (<= val 26)
    
  13.         (code-char (+ val 
    
  14.                           -1
    
  15.                           (char-code #\A)))
    
  16.         " "))
    
  17. ; Calculate how many steps are required.
    
  18. (defun calc (x y)
    
  19.     (let (
    
  20.       (xi (+ OUTPUT_OFFSET_X (* OUTPUT_RES_X (/ x RESOLUTION_X))))
    
  21.       (yi (+ OUTPUT_OFFSET_Y (* OUTPUT_RES_Y (/ y RESOLUTION_Y)))))
    
  22.       (loop for iters below MAX_ITERATIONS
    
  23. 	    for x = 0 then (+ (+ xi (* x x) (* -1 y y)))
    
  24. 	    and y = 0 then (+ yi (* x y 2))
    
  25. 	    when (< 4 (+ (* x x) (* y y)))
    
  26. 	    	do (return iters)
    
  27. 	    finally (return iters))))
    
  28. 	
    
  29. (defun draw_window (width height) 
    
  30.   (dotimes (y height)
    
  31.     (dotimes (x width)
    
  32.         (princ (show (calc x y))))
    
  33.     (terpri)))
    
  34.         
    
  35. (defun main ()
    
  36.     (draw_window RESOLUTION_X RESOLUTION_Y))
    
  37.