# Best way of drawing with turtles

**URL:** <https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166>\
**Category:** Questions & Answers\
**Created:** [July 26, 2023, 8:10am UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166 "2023-07-26T08:10:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![absalom](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/absalom/32/1344_2.png) [@absalom](https://racket.discourse.group/u/absalom)\
**Post date:** [July 26, 2023, 8:10am UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/1 "2023-07-26T08:10:55Z")

</div>

Hi, I have to teach functional programming and I chose Scheme as the main language I will use for that course. I chose DrRacket as the IDE my students will use for obvious practical reasons.

I will stick to R5RS and will not really use racket-specific features except one day: since the students will use DrRacket anyway, and since using recursive functions for drawing fractals is something I find interesting in my teaching, I investigated a bit about a convenient way of using turtles in Racket.

If I understand well, there are two ways of doing it:

- without installing anything more, just typing something like:

```scheme
(require (lib "turtles.ss" "graphics"))
(turtles)
(draw 100)

```

- by installing something called _teachpacks_ (my students will have to type `raco pkg install teachpacks`) and then doing as:

```scheme
(require teachpacks/racket-turtle)
(draw
   (list
      (forward 100)))

```

(and more generally using the documentation at [Racket Turtle](https://docs.racket-lang.org/racket_turtle/index.html))

Is one of these ways better than the other? Of course, for the second one, my students will have to install the library, but I don't think they will get in any trouble. The documentation looks better for that second way, but since I will only draw lines, it doesn't make a big difference either.

---

<div class="post-metadata">

**Author:** ![gus-massa](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/gus-massa/32/507_2.png) [@gus-massa](https://racket.discourse.group/u/gus-massa)\
**Post date:** [July 26, 2023, 2:03pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/2 "2023-07-26T14:03:38Z")

</div>

Small comment: For the first example I prefer

```scheme
(require graphics/turtles)
(turtles)
(draw 100)

```

I'm not sure if there is a difference, but it looks nicer.

[And more importantly, I don't know if the second approach is better or worse.]

---

<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:** [July 26, 2023, 2:28pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/3 "2023-07-26T14:28:47Z")

</div>

If you have the main-distribution package, which most installations do, then you have the htdp package. That provides the graphics/turtles and related modules at [https://docs.racket-lang.org/turtles/index.html](https://docs.racket-lang.org/turtles/index.html). No installation required.

In `#lang racket` and derivatives, using `(require graphics/turtles)` is preferred. Of course, this is not Scheme.

The HTDP turtles library has both "imperative" and "functional" turtles. The teachpack library has what appears to be a rather different set of drawing functions. In the student languages, you can use the "Add Teachpack" menu item from "Languages." (But it gives an error in any other configuration.)

---

<div class="post-metadata">

**Author:** ![absalom](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/absalom/32/1344_2.png) [@absalom](https://racket.discourse.group/u/absalom)\
**Post date:** [July 26, 2023, 3:13pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/4 "2023-07-26T15:13:52Z")

</div>

> [@benknoble](#):
>
> htdp

Thank you for your answer. I was not aware of the functional turtles which look great! I could easily use them from the IDE, but I couldn't figure out how to display the final rendering when running my script from the cli. I only get `(object:turtle-snip% ...)` on my terminal.

---

<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:** [July 27, 2023, 2:42pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/5 "2023-07-27T14:42:16Z")

</div>

Can you share the program? With the regular turtles I can’t reproduce it.

---

<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:** [July 27, 2023, 2:44pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/6 "2023-07-27T14:44:38Z")

</div>

From the docs, I would try something like

```scheme
(define my-turtle …)
(require pict racket/gui)
(show-pict (turtle-pict my-turtle))

```

DrRacket does the “right thing” with snip objects.

You could also try running the program with gracket, but I doubt it makes a difference.

---

<div class="post-metadata">

**Author:** ![absalom](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/absalom/32/1344_2.png) [@absalom](https://racket.discourse.group/u/absalom)\
**Post date:** [July 27, 2023, 3:01pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/7 "2023-07-27T15:01:21Z")

</div>

I tried to display my drawing from the CLI again by using your previous snippet of code, but then I get:

```scheme
koch_functional_turtle.rkt:21:12: turtle-pict: unbound identifier
  in: turtle-pict
  location...:
   koch_functional_turtle.rkt:21:12

```

Do I have to import `turtle-pict`?

---

<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 27, 2023, 3:12pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/8 "2023-07-27T15:12:22Z")

</div>

Yes.

```scheme
(require graphics/value-turtles)

```

---

<div class="post-metadata">

**Author:** ![absalom](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/absalom/32/1344_2.png) [@absalom](https://racket.discourse.group/u/absalom)\
**Post date:** [July 27, 2023, 4:09pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/9 "2023-07-27T16:09:33Z")

</div>

There was a missing "s" in the snippet of code above; I finally could make it work. It should be spelled:

```scheme
(define my-turtle …)
(require pict racket/gui)
(show-pict (turtles-pict my-turtle))

```

---

<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:** [July 27, 2023, 5:23pm UTC](https://racket.discourse.group/t/best-way-of-drawing-with-turtles/2166/10 "2023-07-27T17:23:18Z")

</div>

Oops 🙂 glad you caught that
