# Output of drawings to files

**URL:** <https://racket.discourse.group/t/output-of-drawings-to-files/4139>\
**Category:** Questions & Answers\
**Created:** [March 9, 2026, 10:25pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139 "2026-03-09T22:25:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsampson45](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jsampson45](https://racket.discourse.group/u/jsampson45)\
**Post date:** [March 9, 2026, 10:25pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/1 "2026-03-09T22:25:23Z")

</div>

Is it possible to output a drawing made with the draw module or Metapict or the turtle graphics library to a file such as png or jpeg?

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [March 9, 2026, 10:49pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/2 "2026-03-09T22:49:52Z")

</div>

The `save-pict` function from `metapict` can be used to save picts as png files (or jpeg for that matter).

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [March 9, 2026, 11:00pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/3 "2026-03-09T23:00:17Z")

</div>

Do you mean something like that:

```scheme
#lang racket

(require pict)
(require racket/draw)
(require pict-abbrevs)

(define points '((100 . 100) (0 . 0)))

(define (connect-points dc dx dy join)
  (define a-pen
    (send the-pen-list find-or-create-pen "black" 10 'solid 'round join))
  (send dc set-pen a-pen)
  (send dc draw-lines points dx dy))

(define a-dc
  (dc
   (λ (dc dx dy)
     (define old-pen (send dc get-pen))
     (connect-points dc 20 50 'round)
     (send dc set-pen old-pen))
   460 170))

(save-pict "foo.png" a-dc 'png)

```

---

<div class="post-metadata">

**Author:** ![jsampson45](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jsampson45](https://racket.discourse.group/u/jsampson45)\
**Post date:** [July 17, 2026, 8:51pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/4 "2026-07-17T20:51:43Z")

</div>

No. If I learn how to use turtle graphics in Racket, will I find that I can save the output from it to a file, either as a raster image or vector graphics?

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 17, 2026, 9:23pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/5 "2026-07-17T21:23:26Z")

</div>

There are several turtle libraries.

This example implements the turtle commands, then draws the Peano curve.

> <https://github.com/soegaard/metapict/blob/73aeeb9c98e0fefccb9df614fdaf6ecd421849e1/metapict/examples/peano.rkt#L4>

If you use

> **[Turtle Graphics](https://docs.racket-lang.org/turtles/index.html)**

then use `save-turtle-bitmap `.

If you use

> **[8 2D L-system turtles](https://docs.racket-lang.org/lindenmayer/2D_L-system_turtles.html)**

then you get a pict, which you can then save in different formats.

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [July 17, 2026, 11:10pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/6 "2026-07-17T23:10:12Z")

</div>

> [@jsampson45](#):
>
> If I learn how to use turtle graphics in Racket, will I find that I can save the output from it to a file, either as a raster image or vector graphics?

Essentially all drawing libraries in Racket are higher-level layers over `racket/draw`, which can save a drawing context as SVG, PDF, PostScript, PNG, JPG, and a few miscellaneous raster formats.

Some higher-level libraries for things like turtle graphics may make these things more convenient than others, but the underlying functionality is definitely always there.

---

<div class="post-metadata">

**Author:** ![estrella\_snyder](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@estrella\_snyder](https://racket.discourse.group/u/estrella_snyder)\
**Post date:** [August 2, 2026, 10:54pm UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/7 "2026-08-02T22:54:27Z")

</div>

The turtle example they showed is more about implementing the turtle interface itself — you'd still need to hook it into something that can actually write to a file. Looking at that peano.rkt example, the turtle state is building up a list of line segments, but there's no saving step. You'd want to either render those lines to a pict (which you can then save with save-pict) or draw them to a dc like in the second reply. The dc approach is probably more direct if you're going the turtle route.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [August 3, 2026, 9:42am UTC](https://racket.discourse.group/t/output-of-drawings-to-files/4139/8 "2026-08-03T09:42:46Z")

</div>

The last expression turns the curves into a `pict`.  
If run in DrRacket the image will be displayed in the repl.

```scheme
;;; Produce image
(set-curve-pict-size 400 400)
(with-window (window -1 81 -1 82)
  (peano 6 90 3)
  (draw* c))

```
