[plt-scheme] newbie - plotting points

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Jan 18 12:36:21 EST 2006

The canvas% objects have no memory; you must arrange for your drawing
code to be called on each screen refresh (you can, of course, create a
bitmap and just have your paint callback blit the bits, but this isn't
what happens by default).

Also, you want to avoid creating so many pens; instead use the-pen-list
or the set-pen method as below (it hashes the pens to avoid creating
too many of them).

Finally, it is good practice use modules -- all of our tools (compiler,
module browser, etc) work best when your code is in a module. Its easy
to do, just wrap "(module <fn> mzscheme ...)" around your code, where
<fn> is the filename where you save your code, minus the extension. In
the case below, the file is expected to be in a file called "tmp.ss" or
"tmp.scm".

Use the `module' language to run the program (Use the language|choose
language ... menu item to switch).

(module tmp mzscheme
  (require (lib "mred.ss" "mred")
           (lib "class.ss" "mzlib"))
  
  (define the-frame
    (new frame%
         (label "Hello!")
         (width 400)
         (height 400)))
  
  (define (draw canvas dc)
    (send dc set-pen "red" 5 'solid)
    (send dc draw-point 5 5))
  
  (define the-canvas
    (new canvas%
         (paint-callback draw)
         (parent the-frame)))
  
  (send the-frame show #t))

hth,
Robby

At Wed, 18 Jan 2006 14:20:20 -0300 (CLST), "andrew cooke" wrote:
> Hi,
> 
> I've not programmed much in Lisp or Scheme, and have done nothing at all
> for quite some years, so this may be a very stupid question...
> 
> I'm trying to adapt the example at
> http://schemecookbook.org/Cookbook/GUIHelloWorld to plot a point on an
> empty canvas.  I'm using PLT scheme, just downloaded, with the "Pretty
> Big" language.
> 
> My code, which runs fine, but displays no dot, is below.  Why don't I see
> a red dot near one of the corners of the screen?  (It doesn't work with
> the deafult pen, either).
> 
> Thanks,
> Andrew
> 
> (require (lib "mred.ss" "mred")
>          (lib "class.ss" "mzlib"))
> 
> (define the-frame
>   (new frame%
>        (label "Hello!")
>        (width 400)
>        (height 400)))
> 
> (define the-canvas
>   (new canvas%
>        (parent the-frame)))
> 
> (define the-pen
>   (let ((red (make-object color% 255 0 0)))
>     (make-object pen% red 5 'solid)))
> 
> (define the-dot
>   (let ((dc (send the-canvas get-dc )))
>     (send dc set-pen the-pen)
>     (send dc draw-point 5 5)))
> 
> (send the-frame show #t)
> 
> -- 
> ` __ _ __ ___  ___| |_____   personal site: http://www.acooke.org/andrew
>  / _` / _/ _ \/ _ \ / / -_)  blog: http://www.acooke.org/cute
>  \__,_\__\___/\___/_\_\___|  aim: acookeorg; skype: andrew-cooke
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.