git.haldean.org plotter / master svg.lisp
master

Tree @master (Download .tar.gz)

svg.lisp @masterraw · history · blame

(load "package.lisp")
(load "gathering.lisp")
(in-package :so3-cnc)

(defparameter *svg-head*
  '(
    "<?xml version=\"1.0\" standalone=\"no\"?>"
    "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
    "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
    "<style>"
    "svg { background: #EEE; }"
    "* { fill:none; stroke:#000; stroke-width:0.3; }"
    "</style>"
    ))
(defparameter *svg-tail* '("</svg>"))
(defparameter n 66)

(defun write-svg (polys stream)
  (flet ((write-list (lst) (mapcar (lambda (l) (format stream l)) lst))
         (write-poly (poly) (progn
                           (format stream "<polygon points=\"")
                           (dolist (p poly) (format stream "~,2F ~,2F " (car p) (cdr p)))
                           (format stream "\"/>")
                           )))
    (progn
      (write-list *svg-head*)
      (mapcar #'write-poly polys)
      (write-list *svg-tail*)
      nil
      )))

(defun x.svg (polys)
  (with-open-file (x "x.svg" :direction :output :if-exists :supersede)
    (write-svg polys x)))