| Paste number 49766: | lisp svg examples |
| Pasted by: | fax |
| 9 months, 2 weeks ago | |
| #lispcafe | Context in IRC logs | |
| Paste contents: |
| #|| <?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 width="5cm" height="4cm" version="1.1" xmlns="http://www.w3.org/2000/svg"> <desc>Four separate rectangles </desc> <rect x="0.5cm" y="0.5cm" width="2cm" height="1cm"/> <rect x="0.5cm" y="2cm" width="1cm" height="1.5cm"/> <rect x="3cm" y="0.5cm" width="1.5cm" height="2cm"/> <rect x="3.5cm" y="3cm" width="1cm" height="0.5cm"/> <!-- Show outline of canvas using 'rect' element --> <rect x=".01cm" y=".01cm" width="4.98cm" height="3.98cm" fill="none" stroke="blue" stroke-width=".02cm" /> </svg> ||# (defun test-1 () (let ((svg (make-svg :width 5 :height 4 :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (add-element svg (make-rect :x 0.5 :y 0.5 :width 2 :height 1)) (add-element svg (make-rect :x 0.5 :y 2 :width 1 :height 1.5)) (add-element svg (make-rect :x 3 :y 0.5 :width 1.5 :height 2)) (add-element svg (make-rect :x 3.5 :y 3 :width 1 :height 0.5)) ;; Show outline of canvas using 'rect' element (add-element svg (make-rect :x 0.1 :y 0.1 :width 4.98 :height 3.98 :fill "none" :stroke "blue" :stroke-width 0.2)) (with-open-file (s "/Users/ed/Desktop/test-1.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="5cm" height="5cm" version="1.1" xmlns="http://www.w3.org/2000/svg"> <desc>Two groups, each of two rectangles </desc> <g id="group1" fill="red" > <rect x="1cm" y="1cm" width="1cm" height="1cm" /> <rect x="3cm" y="1cm" width="1cm" height="1cm" /> </g> <g id="group2" fill="blue" > <rect x="1cm" y="3cm" width="1cm" height="1cm" /> <rect x="3cm" y="3cm" width="1cm" height="1cm" /> </g> <!-- Show outline of canvas using 'rect' element --> <rect x=".01cm" y=".01cm" width="4.98cm" height="4.98cm" fill="none" stroke="blue" stroke-width=".02cm" /> </svg> ||# (defun test-2 () (let ((svg (make-svg :width 5 :height 5 :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (add-element svg (make-desc "Two groups, each of two rectangles")) (let ((group-1 (make-group :id "group1" :fill "red"))) (add-element group-1 (make-rect :x 1 :y 1 :width 1 :height 1)) (add-element group-1 (make-rect :x 3 :y 1 :width 1 :height 1)) (add-element svg group-1)) (let ((group-2 (make-group :id "group1" :fill "blue"))) (add-element group-2 (make-rect :x 1 :y 3 :width 1 :height 1)) (add-element group-2 (make-rect :x 3 :y 3 :width 1 :height 1)) (add-element svg group-2)) ;; Show outline of canvas using 'rect' element (add-element svg (make-rect :x 0.1 :y 0.1 :width 4.98 :height 4.98 :fill "none" :stroke "blue" :stroke-width 0.02)) (with-open-file (s "/Users/ed/Desktop/test-2.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="10cm" height="3cm" viewBox="0 0 100 30" xmlns="http://www.w3.org/2000/svg" version="1.1"> <desc>Example Use03-GeneratedContent - 'use' with a 'transform' attribute</desc> <!-- 'defs' section left out --> <rect x=".1" y=".1" width="99.8" height="29.8" fill="none" stroke="blue" stroke-width=".2" /> <!-- Start of generated content. Replaces 'use' --> <g transform="translate(20,2.5) rotate(10)"> <rect x="0" y="0" width="60" height="10"/> </g> <!-- End of generated content --> </svg> ||# (defun test-3 () (let ((svg (make-svg :width 10 :height 3 :|viewBox| "0 0 100 30" :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (let ((group (make-group :transform "translate(20,2.5) rotate(10)"))) (add-element group (make-rect :x 0 :y 0 :width 60 :height 10)) (add-element svg group)) ;; Show outline of canvas using 'rect' element (add-element svg (make-rect :x 0.1 :y 0.1 :width 99.8 :height 29.8 :fill "none" :stroke "blue" :stroke-width 0.02)) (with-open-file (s "/Users/ed/Desktop/test-3.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="5cm" height="4cm" viewBox="0 0 500 400" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example cubic01- cubic Bezier commands in path data</title> <desc>Picture showing a simple example of path data using both a "C" and an "S" command, along with annotations showing the control points and end points</desc> <style type="text/css"><![CDATA[ .Border { fill:none; stroke:blue; stroke-width:1 } .Connect { fill:none; stroke:#888888; stroke-width:2 } .SamplePath { fill:none; stroke:red; stroke-width:5 } .EndPoint { fill:none; stroke:#888888; stroke-width:2 } .CtlPoint { fill:#888888; stroke:none } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .Label { font-size:22; font-family:Verdana } ]]></style> <rect class="Border" x="1" y="1" width="498" height="398" /> <polyline class="Connect" points="100,200 100,100" /> <polyline class="Connect" points="250,100 250,200" /> <polyline class="Connect" points="250,200 250,300" /> <polyline class="Connect" points="400,300 400,200" /> <path class="SamplePath" d="M100,200 C100,100 250,100 250,200 S400,300 400,200" /> <circle class="EndPoint" cx="100" cy="200" r="10" /> <circle class="EndPoint" cx="250" cy="200" r="10" /> <circle class="EndPoint" cx="400" cy="200" r="10" /> <circle class="CtlPoint" cx="100" cy="100" r="10" /> <circle class="CtlPoint" cx="250" cy="100" r="10" /> <circle class="CtlPoint" cx="400" cy="300" r="10" /> <circle class="AutoCtlPoint" cx="250" cy="300" r="9" /> <text class="Label" x="25" y="70">M100,200 C100,100 250,100 250,200</text> <text class="Label" x="325" y="350" style="text-anchor:middle">S400,300 400,200</text> </svg> ||# (defun test-4 () (let ((svg (make-svg :width 5 :height 4 :|viewBox| "0 0 500 400" :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (add-element svg (make-css " .Border { fill:none; stroke:blue; stroke-width:1 } .Connect { fill:none; stroke:#888888; stroke-width:2 } .SamplePath { fill:none; stroke:red; stroke-width:5 } .EndPoint { fill:none; stroke:#888888; stroke-width:2 } .CtlPoint { fill:#888888; stroke:none } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .Label { font-size:22; font-family:Verdana }")) ;; Show outline of canvas using 'rect' element (add-element svg (make-rect :class "Border" :x "1" :y "1" :width "498" :height "398")) (add-element svg (make-polyline :class "Connect" :points "100,200 100,100")) (add-element svg (make-polyline :class "Connect" :points "250,100 250,200")) (add-element svg (make-polyline :class "Connect" :points "250,200 250,300")) (add-element svg (make-polyline :class "Connect" :points "400,300 400,200")) (add-element svg (make-path :class "SamplePath" :d "M100,200 C100,100 250,100 250,200 S400,300 400,200")) (add-element svg (make-circle :class "EndPoint" :cx "100" :cy "200" :r "10")) (add-element svg (make-circle :class "EndPoint" :cx "250" :cy "200" :r "10")) (add-element svg (make-circle :class "EndPoint" :cx "400" :cy "200" :r "10")) (add-element svg (make-circle :class "CtlPoint" :cx "100" :cy "100" :r "10")) (add-element svg (make-circle :class "CtlPoint" :cx "250" :cy "100" :r "10")) (add-element svg (make-circle :class "CtlPoint" :cx "400" :cy "300" :r "10")) (add-element svg (make-circle :class "AutoCtlPoint" :cx "250" :cy "300" :r "9")) (add-element svg (make-text "M100,200 C100,100 250,100 250,200" :class "Label" :x "25" :y "70")) (add-element svg (make-text "S400,300 400,200" :class "Label" :style "text-anchor:middle" :x "325" :y "350")) (with-open-file (s "/Users/ed/Desktop/test-4.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="12cm" height="4cm" viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1"> <desc>Example rect02 - rounded rectangles</desc> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="1198" height="398" fill="none" stroke="blue" stroke-width="2"/> <rect x="100" y="100" width="400" height="200" rx="50" fill="green" /> <g transform="translate(700 210) rotate(-30)"> <rect x="0" y="0" width="400" height="200" rx="50" fill="none" stroke="purple" stroke-width="30" /> </g> </svg> ||# (defun test-5 () (let ((svg (make-svg :width 12 :height 4 :|viewBox| "0 0 1200 400" :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (add-element svg (make-desc "Example rect02 - rounded rectangles")) (add-element svg (make-rect :x "1" :y "1" :width "1198" :height "398" :fill "none" :stroke "blue" :stroke-width "2")) (add-element svg (make-rect :x "100" :y "100" :width "400" :height "200" :rx "50" :fill "green")) (let ((group (make-group :transform "translate(700 210) rotate(-30)"))) (add-element group (make-rect :x "0" :y "0" :width "400" :height "200" :rx "50" :fill "none" :stroke "purple" :stroke-width "30")) (add-element svg group)) (with-open-file (s "/Users/ed/Desktop/test-5.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="10cm" height="3cm" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" version="1.1"> <desc>Example tspan01 - using tspan to change visual attributes</desc> <g font-family="Verdana" font-size="45" > <text x="200" y="150" fill="blue" > You are <tspan font-weight="bold" fill="red" >not</tspan> a banana. </text> </g> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="998" height="298" fill="none" stroke="blue" stroke-width="2" /> </svg> ||# (defun test-6 () (let ((svg (make-svg :width 10 :height 3 :|viewBox| "0 0 1000 300" :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (let ((group (make-group :font-family "Verdana" :font-size "45"))) (let ((text (make-text "You are " :x "200" :y "150" :fill "blue"))) (add-element text (make-tspan "not" :font-weight "bold" :fill "red")) (add-element text " a banana.") (add-element group text)) (add-element svg group)) (with-open-file (s "/Users/ed/Desktop/test-6.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) #|| <?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 width="10cm" height="3cm" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" version="1.1"> <desc>Example tspan03 - using tspan's x and y attributes for multiline text and precise glyph positioning</desc> <g font-family="Verdana" font-size="45" > <text fill="rgb(255,164,0)" > <tspan x="300 350 400 450 500 550 600 650" y="100"> Cute and </tspan> <tspan x="375 425 475 525 575" y="200"> fuzzy </tspan> </text> </g> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="998" height="298" fill="none" stroke="blue" stroke-width="2" /> </svg> ||# (defun test-7 () (let ((svg (make-svg :width 10 :height 3 :|viewBox| "0 0 1000 300" :version "1.1" :xmlns "http://www.w3.org/2000/svg"))) (let ((group (make-group :font-family "Verdana" :font-size "45"))) (let ((text (make-text () :fill "rgb(255,164,0)"))) (add-element text (make-tspan "Cute and " :x "300 350 400 450 500 550 600 650" :y "100")) (add-element text (make-tspan " fuzzy" :x "375 425 475 525 575" :y "200")) (add-element group text)) (add-element svg group)) (with-open-file (s "/Users/ed/Desktop/test-7.svg" :direction :output :if-exists :supersede :if-does-not-exist :create) (print-svg svg s)))) |
This paste has no annotations.