chsms
chsms

Reputation: 107

Draw an arrow in racket

How to draw an arrow in a frame in racket (DrRacket)? For example between two objects: a circle and a rectangle obtained by:

(send dc draw-ellipse 50 50 30 30) and (send dc draw-rectangle 200 200 30 6)

Upvotes: 1

Views: 913

Answers (2)

David Merinos
David Merinos

Reputation: 1295

You can use picts to do such things.

First, you define your picts.

(define pict-a (rectangle 40 40))

(define pict-b (circle 40))

Then you combine them to be able to use rc-find or lc-find, which are the procedures that will help you connect those picts.

(define combined (hc-append 200 pict-a pict-b))

Finally

> (pin-arrows-line 30 combined
                   pict-a rc-find
                   pict-b lc-find
                   #:start-angle (/ pi 11)
                   #:end-angle (- (/ pi 11))
                   #:solid? #f)

Will produce this: Two picts connected

You can find more information in the docs! Tell us if that solved your problem!

Upvotes: 2

soegaard
soegaard

Reputation: 31147

What kind of arrows?

  • For simple arrows use draw-line directly.
  • For bended arrows use draw-spline. Use a filled triangle as a simple arrow head.

If you need a prettier arrow head shape, one option is to adapt the arrow shape from MetaPict.

You can find other examples of arrows in MetaPict's documentation.

An example with a non-straight arrow which shows how to draw a state machine with MetaPict.

Upvotes: 1

Related Questions