Created
July 6, 2013 01:46
-
-
Save mohiji/5938267 to your computer and use it in GitHub Desktop.
Really basic demo of cl-pdf: in this case drawing boxes for doing 3.5" iPhone mockups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; iphone-template.lisp | |
;; Quicky code to generate an iPhone template for sketching out ideas. | |
;; | |
;; To use it, make sure you have cl-pdf available, e.g. (ql:quickload "cl-pdf"), | |
;; then just run (iphone-template:write-template "/path/to/output.pdf") | |
(require 'cl-pdf) | |
(defpackage :iphone-template | |
(:use :cl) | |
(:export write-template)) | |
(in-package :iphone-template) | |
(defconstant +points-per-inch+ 72) | |
(defconstant +points-margin+ 36) | |
(defparameter *iphone-inches-wide* 2.76) | |
(defparameter *iphone-inches-high* 1.9) | |
(defparameter *iphone-points-wide* (* *iphone-inches-wide* +points-per-inch+)) | |
(defparameter *iphone-points-high* (* *iphone-inches-high* +points-per-inch+)) | |
(defun draw-box (x y width height) | |
(let* ((left x) | |
(right (+ x width)) | |
(bottom y) | |
(top (+ bottom height))) | |
(pdf:move-to left bottom) | |
(pdf:line-to left top) | |
(pdf:line-to right top) | |
(pdf:line-to right bottom) | |
(pdf:line-to left bottom))) | |
(defun write-template (path) | |
(pdf:with-document () | |
(pdf:with-page (:bounds pdf:*letter-portrait-page-bounds*) | |
(let ((left 72) | |
(bottom 72) | |
; offset values determined by writing out the math by hand | |
(vertical-offset (+ 25.919983 *iphone-points-wide*)) | |
(horizontal-offset (+ 28.799988 *iphone-points-high*))) | |
(dotimes (y 3) | |
(dotimes (x 3) | |
(draw-box (+ left (* x horizontal-offset)) | |
(+ bottom (* y vertical-offset)) | |
*iphone-points-high* *iphone-points-wide*)))) | |
(pdf:set-rgb-stroke 0.5 0.5 0.5) | |
(pdf:stroke)) | |
(pdf:write-document path))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment