[plt-scheme] newbie - plotting points

From: andrew cooke (andrew at acooke.org)
Date: Wed Jan 18 16:08:59 EST 2006

Thanks; that's all very helpful.

But maybe I should have asked a more high-level question: Is there some
toolkit or other GUI class I should be using that lets me plot points,
maybe draw lines?  It doesn't have to be a full-blown plotting package,
but I'm thinking that wiring up a bitmap to provide permanent backing
store for a canvas is the kind of thing that has already been done once.

To give you some idea of what I'm doing - I looked at this page
http://blogs.msdn.com/code4bill/archive/2005/12/20/505872.aspx and thought
"Hmmm, I wonder if I would see a pattern if I plotted dots relating
decimal numbers on one axis to progressive incrementing "Fibonacci
numbers" on the other axis?".

So the idea is to do simple exploratory graphical analysis.  I was going
to use Python then I realised that I didn't know what plotting package to
use there and that I might as well give scheme a try-out since this was a
nice toy problem....

Thanks,
Andrew


Robby Findler wrote:
> 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.