;; Mandelbrot set in chiklisp (mod (X1 Y1 X2 Y2 STEP) (include *standard-cl-21*) (defconstant LIMIT 0x0400) (defconstant MAXITERS 15) (defconstant CHARS "0123456789ABCDEF") (defun print (M P) (if (all "$print$" M P) P P)) (defun to-char (V) (c 1 (substr CHARS V (+ 1 V))) ) (defun escape-steps (X Y WX WY V) (if (> MAXITERS V) (let ((xsqr (ash (* X X) -8)) (ysqr (ash (* Y Y) -8))) (if (> (+ xsqr ysqr) LIMIT) (- V 1) (let ((next-x (+ (- xsqr ysqr) WX)) (next-y (+ (* 2 (ash (* X Y) -8)) WY))) (escape-steps next-x next-y WX WY (+ 1 V)) ) ) ) (- V 1) ) ) (defun basic-scanline (X1 Y1 X2 STEP) (if (> X2 X1) (let ((escape (print (list "escape-at" X1 Y1) (escape-steps 0 0 X1 Y1 0))) (rest (basic-scanline (+ X1 STEP) Y1 X2 STEP))) (c (to-char escape) rest) ) () ) ) (defun stringify-row (R) (a (c 14 (c (c 1 "|") R)) ()) ) (defun scan (X1 Y1 X2 Y2 STEP) (if (> Y2 Y1) (c (c 1 (stringify-row (basic-scanline X1 Y1 X2 STEP))) (scan X1 (+ STEP Y1) X2 Y2 STEP)) () ) ) (print "result" (stringify-row (scan X1 Y1 X2 Y2 STEP))) )