Skip to content

Instantly share code, notes, and snippets.

@spdegabrielle
Created December 31, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spdegabrielle/c85fc5ffba8c406163be56f214b7d86e to your computer and use it in GitHub Desktop.
Save spdegabrielle/c85fc5ffba8c406163be56f214b7d86e to your computer and use it in GitHub Desktop.
how to save an svg in Sketching
A couple of days a ago it was discussed how to save an svg in Sketching. Here is an example.
```
#lang sketching
(require (only-in racket/draw svg-dc%)
(only-in sketching/parameters current-dc))
(define WIDTH 200)
(define HEIGHT 200)
(define OUTPUT "my-svg.svg")
(define (setup)
(no-loop)
(size WIDTH HEIGHT))
(define (draw)
; create a new svg
(define an-svg-dc
(new svg-dc%
[width width]
[height height]
[output OUTPUT]
[exists 'replace])) ; overwrite existing file
; An svg is a document with a series of pages
(an-svg-dc.start-doc "My Drawing")
(an-svg-dc.start-page)
; tell sketching to draw to the svg drawing context
(current-dc an-svg-dc)
(rect-mode 'center)
(translate 100 100) ; place the center in (100,100)
(square 0 0 50)
(line -25 25 25 -25)
; end page and document (saves it)
(an-svg-dc.end-page)
(an-svg-dc.end-doc))
```
@spdegabrielle
Copy link
Author

Posted by @soegaard on Racket Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment