# Scribble-compatible image drawing libraries

**URL:** <https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081>\
**Category:** Questions & Answers\
**Tags:** question, scribble, pict, image\
**Created:** [June 14, 2022, 10:37am UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081 "2022-06-14T10:37:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)\
**Post date:** [June 14, 2022, 10:38am UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/1 "2022-06-14T10:38:00Z")

</div>

I'd like to create images similar to the ones [on this page](https://www.scheme.com/tspl4/start.html) (not the one on the top though 😉 ) and include them in a Scribble document. So these images would consist mostly of text, boxes, lines and arrows.

The [Scribble documentation](https://docs.racket-lang.org/scribble/getting-started.html#%28part._pictures%29) (section "Pictures") mentions two possibilites to directly include images generated by Racket code: [Pict](https://docs.racket-lang.org/pict/index.html) and [2htdp/image](https://docs.racket-lang.org/teachpack/2htdpimage.html).

I have no experience with Pict and only very little with 2htdp/image. Since both libraries seem to take some time to learn and use, I would like to settle on one library before diving into it. From looking at the documentation of the two libraries, my impression is that the Pict library would be better for my use case. What do you think?

Are there any other "Scribble-compatible" libraries for drawing simple images (as described above) that you would recommend?

---

<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:** [June 14, 2022, 12:30pm UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/2 "2022-06-14T12:30:43Z")

</div>

For HtDP, I started with mostlt 2htdp/images and some picts for diagrams. As it came time to publish, I went all pict. So there’s some experience.

Let’s compare:

## 2htdp/image

- smooth learning curve
- pretty powerful for a teachpack
- a “CS1” teacher (middle, high, freshman) can use the code for write-ups and for demos

## pict

- somewhat steeper learning curve
- somewhat different “work"; think `(rectangle 100 200 “solid” “green”)` vs `(rectangle 100 100 #:border-color "green" #:border-width 100)` vs `(filled-rectangle 100 100 #:color “green”)` — the second is NOT what you really want
- supports racket code (for slideshows for example)
- more power (drop down and draw into the dc if you want more than pict offers)
- sharp pictures, ready for commercial printing; relative easy to turn off colors for pict code  
[[This might have been my lack of understanding all the knobs and dials in 2htdp/image, which is Robby and Ian's even if I added a few lines of code here and there.]]
- easily usable for PDF and HTML output (though you should go through SVG and scale differently)

If this doesn’t help you make a decision, ask.

p.s. I initially wrote a little module in pict so I could port 2htdp/image easily to pict. Not worth the effort.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [June 14, 2022, 12:41pm UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/3 "2022-06-14T12:41:31Z")

</div>

FWIW, there are some constructs of each that are intercompatible. For example, in a current project I am using 2htdp/image's wedge and triangle along with constructs from pict, pict/flash, and pict/color.

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [June 14, 2022, 3:03pm UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/4 "2022-06-14T15:03:54Z")

</div>

On the general point, `pict` is more full-featured and aimed at general use cases, whereas `2htdp/image` is aimed at teaching and beginning programmers but has more shapes built-in.

On your specific goal, I think this library is what you want: [Sdraw: Cons-Cell Diagrams with Pict](https://docs.racket-lang.org/sdraw/index.html)

---

<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:** [June 14, 2022, 3:44pm UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/5 "2022-06-14T15:44:58Z")

</div>

Depending on the type of figure you need, MetaPict is an option too.  
MetaPict produces picts, so you can use them just as images produces by `pict`.

Box and pointers

> <https://github.com/soegaard/metapict/blob/47ae265f73cbb92ff3e7bdd61e49f4af17597fdf/metapict/box-and-pointer-diagram.rkt>

Docs: [MetaPict](https://docs.racket-lang.org/metapict/index.html)

Video: [Jens Axel Søgaard — MetaPict - YouTube](https://www.youtube.com/watch?v=7Kf8Kk8NPFw)

---

<div class="post-metadata">

**Author:** ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)\
**Post date:** [June 14, 2022, 5:39pm UTC](https://racket.discourse.group/t/scribble-compatible-image-drawing-libraries/1081/6 "2022-06-14T17:39:50Z")

</div>

Thanks for your answers, everyone! 🙂

@EmEf @samth From what you write, I'd rule out `2htdp/image` for now.

@benknoble Interesting to know they can be mixed. @EmEf wrote that the picture quality of `pict` is better. I wonder what that means for `2htdp/image` "subimages" in `pict` images.

> [@samth](#):
>
> On your specific goal, I think this library is what you want: [Sdraw: Cons-Cell Diagrams with Pict](https://docs.racket-lang.org/sdraw/index.html)

It's quite impressive. At the moment I think I won't use it though because

- I want to draw also pictures of vectors and maybe hashes (although I'm not sure if the latter makes any sense 😉 ), but I could use (for example) `pict` for that as long as I can reproduce the line widths and arrows that `sdraw` uses.
- Since the `car` values are pointed to outside the cons cell boxes, the images look rather "noisy" (for lack of a better word). I see the point for this (in case the car values don't fit in the box), but I expect to use only things like short numbers or symbols. I'm also open to making the boxes a bit larger if needed.

@soegaard `metapict` looks quite interesting (also, but by far not only, because of the box and pointers example). So it's now deciding between `metapict` and `pict`. I'll read the packages' documentation more thoroughly now and make some experiments to decide.

That said, if someone has more library suggestions, I'm curious. And even if I don't use them for now, it may be interesting for others who search the forum later.

**Edit:** In the end, I went with `pict`, but during that, I several times thought of just using LibreOffice Draw. 😉
