How to draw an arc with module `graphics/turtles`?

21 views
Skip to first unread message

Killian Zhuo (KDr2)

unread,
Feb 1, 2021, 6:54:05 PM2/1/21
to Racket Users
I am imitating the Logo API to draw some shapes with `graphics/turtles`, but in it I only find functions to draw lines, is there a way to draw an arc?



Greetings.

Killian Zhuo (KDr2, https://kdr2.com)

making-a-racket

unread,
Feb 1, 2021, 10:31:52 PM2/1/21
to Racket Users
Turtles can only turn or move forward with or without drawing. To draw an arc, you'll need to combine these methods to do that.

I highly recommend the book Turtle Geometry by Abelson and diSessa. Below you can find an excerpt of the book that talks about drawing circles and arcs.

turtle.PNG

Here's an implementation of a circle in Racket using the turtle library you referenced.

#lang racket

(require graphics/turtles)

(turtles #t)

(for ([i (in-range 360)])
  (draw 1)
  (turn 1))

Killian Zhuo (KDr2)

unread,
Feb 2, 2021, 3:34:14 AM2/2/21
to Racket Users, making-a-racket
Thank you, I just implemented a UCBLogo compatible `arc`:

(define (arc angle radius)
  (let* ([alpha (* 2 (asin (/ 1 (* 2 radius))))]
         [rangle (* pi (/ angle 180))]
         [n (abs (/ rangle alpha))]
         [astep (if (> angle 0) (- alpha) alpha)])
    (tprompt
     (move radius)
     (turn (if (> angle 0) -90 90))
     (for ([i (in-range n)])
       (draw 1)
       (turn/radians astep)))
    (turn (- angle))))
Here's an implementation of a circle in Racket using the turtle library you referenced.

#lang racket

(require graphics/turtles)

(turtles #t)

(for ([i (in-range 360)])
  (draw 1)
  (turn 1))

On Monday, February 1, 2021 at 5:54:05 PM UTC-6 zhuo...@gmail.com wrote:
> I am imitating the Logo API to draw some shapes with `graphics/turtles`, but in it I only find functions to draw lines, is there a way to draw an arc?
>
>
>
> Greetings.
>
> Killian Zhuo (KDr2, https://kdr2.com)


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/aea4ad53-162e-4924-87ed-1e7311c2aef3n%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages