; Draws the famous curve of Koch. ; Alejandro Luque Estepa, 1999 ;First of all, we load the LispGraph package... (import "zlisp.LispGraph") (defun intercala (l p) (cond ((nullp (cdr l)) (append l p)) (t (append (cons (car l) p) (intercala (cdr l) p))) ) ) (defun nintercala (l p n) (cond ((equal n 1) (intercala l p)) (t (intercala (nintercala l p (sub1 n)) p )) ) ) (defun mtortuga (s a) (prog nil (right a) (forward s)) ) (defun camino (s p) (applytoall '(lambda (x) (mtortuga s x)) p) ) ; The old-known curve of Koch (defun koch (s n) (camino s (nintercala '(0 120 120) '(-60 120 -60) n)) ) ; A square variant (defun square_koch (s n) (camino s (nintercala '(0 90 90 90) '(-90 90 90 -90) n)) ) (if (not (equal 0.1 1)) (defun koch_sample nil (prog nil (cls 0.0 0.0 0.5) (color 1.0 1.0 0.0) (turtle 120 65 0) (pendown) (koch 3 4) ) ) (defun koch_sample nil (prog nil (cls 0,0 0,0 0,5) (color 1,0 1,0 0,0) (turtle 120 65 0) (pendown) (koch 3 4) ) ) ) (msg "Usage: (koch s n) draws a Koch's curve of order n with segments of length s" t) (msg "To view an example write (koch_sample) and evaluate while in graphics mode" t)