Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.02 KB | None | 0 0
  1. (ql:quickload 'cl-svg)
  2.  
  3. (use-package 'cl-svg)
  4.  
  5. (defparameter +height+ 133.4)
  6. (defparameter +hp+ 5.08) ;Horizontal pitch
  7.  
  8. (defparameter +hole-offet-vertical+ 3.0) ;Distance from edge of module and screw hole
  9. (defparameter +hole-offet-horizontal+ 7.5) ;Distance from edge of module and screw hole
  10.  
  11. (defvar *width*)
  12. (setf *width* 4)
  13.  
  14. (defparameter +screw-radius+ "1.75")
  15. (defparameter +x-offset+ 3.5)
  16. (defparameter +y-offset+ 3.5)
  17.  
  18. (let* ((scene (make-svg-toplevel 'svg-1.1-toplevel :height "150mm" :width "150mm"
  19.                                  :viewBox "0 0 150 150")))
  20.   (draw scene (:path :d (path (move-to 0 0) ; Generate outline of module
  21.                           (line-to (* *width* +hp+) 0)
  22.                           (line-to (* *width* +hp+) +height+)
  23.                           (line-to 0 +height+)
  24.                           (line-to 0 0)
  25.                           (close-path)) :stroke "red" :stroke-width "1" :fill "white"))
  26.   (screw-hole scene 'top-left)
  27.   (screw-hole scene 'top-right)
  28.   (screw-hole scene 'bottom-right)
  29.   (screw-hole scene 'bottom-left)
  30.   (with-open-file (s "test.svg" :direction :output :if-exists :supersede)
  31.     (stream-out s scene)))
  32.  
  33. (deftype screw-positions () '(member top-left top-right
  34.                               bottom-left bottom-right))
  35.  
  36. (defun screw-hole (scene position)
  37.   "Place a screw hole"
  38.   (let* ((x-offset 0)
  39.          (y-offset 0))
  40.     (cond ((eq position 'top-left) (setf x-offset +x-offset+)
  41.            (setf y-offset +y-offset+))
  42.  
  43.           ((eq position 'top-right) (setf x-offset (- (* +hp+ *width*) +x-offset+))
  44.            (setf y-offset +y-offset+))
  45.  
  46.           ((eq position 'bottom-left) (setf x-offset +x-offset+)
  47.            (setf y-offset (- +height+ +y-offset+)))
  48.  
  49.           ((eq position 'bottom-right) (setf x-offset (- (* +hp+ *width*) +x-offset+))
  50.            (setf y-offset (- +height+ +y-offset+))))
  51.     (draw scene (:circle :cx x-offset :cy y-offset :r +screw-radius+ :stroke "red" :fill "white"
  52.                          :stroke-width "1"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement