[racket] Very simple animation in #racket/gui

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Jan 23 13:32:10 EST 2015

#lang racket
(require racket/gui/base)

(define x 0)

(define frame (new frame% [label "Frame"] [width 500] [height 500]))
(define canvas (new canvas% [parent frame]
                    [paint-callback
                     (λ (c dc)
                       (send dc set-pen "red" 4 'solid)
                       (send dc clear)
                       (send dc draw-line x 250 x 250))]))
(send frame show #t)


(define (loop)
  (send canvas on-paint)
  (set! x (remainder (+ x 1) 500))
  (sleep/yield 0.02)
  (loop))

(loop)

2015-01-23 17:48 GMT+01:00 Alexandr M <rus314 at gmail.com>:
> Hello dear community members,
>
> I am trying to build a GUI with a very simple animation - just a moving dot
> (or vertical line) from the left side of the canvas object to it's right
> side.
>
> There is a section called "1.7 Animation in Canvases" in the racket
> documentation:
>
> http://docs.racket-lang.org/gui/windowing-overview.html#%28part._animation%29
>
> But it's very short and without examples.
>
> Could you please point me out where to search or maybe give me actual
> example how to implement this using racket/gui ? I know there are
> matlab-like plotting libs but I am going to build GUI with a lot of buttons
> and parameters, I don't need just a plot, that's why I am asking about
> implementation in #racket/gui environment.
>
> Thank you in advance.
>
> --
> Best regards,
> Alex
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
--
Jens Axel Søgaard


Posted on the users mailing list.