[racket] is anyone using racket to generate animated diagrams?

From: Martin DeMello (martindemello at gmail.com)
Date: Mon Sep 22 16:06:54 EDT 2014

Thanks, metapict looks great!

martin

On Mon, Sep 22, 2014 at 12:44 PM, Jens Axel Søgaard <jensaxel at soegaard.net>
wrote:

> Hi Martin,
>
> As an example I implemented the standing wave animation.
>
> The MetaPict package is available through the package system.
> Use the package manager in DrRacket to install install it.
> The run the program below in DrRacket to see a standing wave.
>
> The documentation of the MetaPict package is here:
>     http://soegaard.github.io/docs/metapict/metapict.html
>
> Enjoy,
> Jens Axel
>
> #lang racket
> (require metapict
>          metapict/graph
>          (only-in 2htdp/universe animate)
>          (only-in 2htdp/image freeze))
>
> (set-curve-pict-size 400 100)  ; size 400 x 100 pixels
>
> ; red-circle : point -> pict
> ;  red disk with center in the point p drawn with black periphery
> (define (red-circle p)
>   (def c (circle p 0.1))
>   (draw (color "red" (fill c)) ; red, filled circle
>         c))                    ; black outline
>
>
> (define N 100) ; number of frames in the animation
> (define (f m)
>   ; The function to graph at time t is cos(ωt)*sin(kx), where t is in
> [0;2pi].
>   ; First we convert the frame number to time:
>   (define t (* 2 pi (/ (remainder m N) N)))
>   (define ω 1) ; angular frequency
>   (define k 1) ; wave number
>   ; The actual function to graph
>   (λ (x) (* (cos (* ω t)) (sin (* k x)))))
>
>
> (define (animation-frame m)
>   (with-window (window/aspect -0.2 (+ (* 4 pi) 0.2) ; x in [-0.1, 4pi+0.1]
>                               -1.2)             ; y in [-0.1, 1.1]
>     (pict->bitmap ; animate needs bitmaps
>      (draw
>       ; graph the function f from 0 to 4pi
>       (graph (f m) 0 (* 4 pi))
>       ; five red dots at the nodes (0,0), (pi,0), ...
>       (for/draw ([n 5])
>           (red-circle (pt (* n pi) 0)))))))
>
> ; animate them!
> (animate animation-frame)
>
>
>
> 2014-09-22 20:49 GMT+02:00 Martin DeMello <martindemello at gmail.com>:
> > I was looking through http://en.wikipedia.org/wiki/User:LucasVB/Gallery
> > (generated, according to the author, with a combination of php and
> libgd),
> > and wondered if anyone was doing similar stuff in racket. I'd love to see
> > code samples if so.
> >
> > martin
> >
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
> >
>
>
>
> --
> --
> Jens Axel Søgaard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140922/18053100/attachment-0001.html>

Posted on the users mailing list.