[racket] Programmatic drawing

19 views
Skip to first unread message

C K Kashyap

unread,
Oct 30, 2014, 2:19:40 PM10/30/14
to users
Dear Racket folks,

I'd like to use Dr Racket to generate some drawings. I liked the way I can compose and create images using slideshow. I could not figure how I could draw arbitrary curves though?

When I looked for it I found the racket/draw package. Can the racket/draw functions be used along with slideshow? 

Or is there any other recommended package for achieving interactive drawing creation?

Regards,
Kashyap

Matthew Flatt

unread,
Oct 30, 2014, 2:32:14 PM10/30/14
to C K Kashyap, users
Yes, the `dc` pict constructor provides a bridge between `racket/draw`
and picts:

#lang slideshow

(slide
(dc (lambda (dc x y)
(send dc draw-spline
x y
(+ x 20) (+ y 80)
(+ x 100) (+ y 100)))
100 100))
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
____________________
Racket Users list:
http://lists.racket-lang.org/users

Jens Axel Søgaard

unread,
Oct 30, 2014, 3:53:17 PM10/30/14
to C K Kashyap, users
MetaPict supports arbitrary curves and will produce picts.

http://soegaard.github.io/docs/metapict/metapict.html

Given points p, q, r, ... and vectors (directions) d, e, f ... :

(curve p .. q .. r .. s) draws a "nice" curve from p through q and r to s
(curve p .. q d .. r .. s) draws a "nice" curve from p through q and r to s,
and the curve leaves q in the direction d
(curve p .. q .. r .. cycle) draws a closed curve through p, q and r
(curve p .. q .. r -- s .. t) draws a curve from p through q to r then
a line from r to s and finally
curves to t

There is a ton of examples here:
https://github.com/soegaard/metapict/blob/master/metapict/examples/metapost-examples.rkt

/Jens Axel

> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>

--
--
Jens Axel Søgaard

C K Kashyap

unread,
Oct 30, 2014, 10:41:45 PM10/30/14
to Jens Axel Søgaard, users
Wow ... Thanks Mathew and Jens.

I think, in future I should just ask "how do I do such and such" - "can I do such and such is an unnecessary question in racket" :)

Regards,
Kashyap
Reply all
Reply to author
Forward
0 new messages