;; Copyright (c) 2006, Sarken LLC ;; Contact: Gordon Fischer [ fischer@sarken.org ] ;; Released under the Creative Commons Attribution License ;; http://creativecommons.org/licenses/by/2.5/ ;; Based on the following Perl code [ http://brevity.org/code/google/google-draw-pl.txt ] # Copyright (c) 2005, Neil Kandalgaonkar # Released under the BSD license # http://www.opensource.org/licenses/bsd-license.php ;; Draw takes a list of coordinates. ;; First pair is absolute, following are relative to first pair. (context 'GOOGLE) (set 'test-clist-rel '( (10 10) (20 0) (0 20) (-20 0) (0 -20) )) (set 'test-clist-abs '( (10 10) (30 10) (30 30) (10 30) (10 10) )) (define (Draw-rel clist , e f path) (set 'path "") (push 9999 clist -1) ;; end of stream marker (dolist (c (flat clist)) (set 'f (- (* (abs c) 2) (if (< c 0) 1 0))) (do-while (!= 0 f) (set 'e (& f 31)) (set 'f (>> f 5)) (if (> f 0) (set 'e (| e 32))) (write-buffer path (char (+ e 63))) ) ) path ) (define (Draw a , b max_x max_y results) (set 'b (transpose a)) (set 'max_x (apply max (b 0))) (set 'max_y (apply max (b 1))) (set 'b a) (push '(0 0) a) (push '(0 0) b -1) (dotimes (x (length a)) (push (list (- (b x 0) (a x 0)) (- (b x 1) (a x 1))) results -1)) (pop results -1) (string "http://www.google.com/maplinedraw?width=" (+ max_x 10) "&height=" (+ max_y 10) "&path=" (Draw-rel results)) ) (context 'MAIN) ;; This will generate a URL that draws a square ;; (GOOGLE:Draw GOOGLE:test-clist-abs)