Created
December 31, 2021 14:41
-
-
Save spdegabrielle/c85fc5ffba8c406163be56f214b7d86e to your computer and use it in GitHub Desktop.
how to save an svg in Sketching
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
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)) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Posted by @soegaard on Racket Discord