[racket] draw circle over bitmap and erase old circle

From: Richard Cleis (rcleis at mac.com)
Date: Thu Oct 28 02:14:32 EDT 2010

Incremental changes like this can work, but a good program design is necessary to prevent running into situations that cannot be solved with a few hacks. I cannot suggest a better way without knowing your goals.

By the way, in the email I intended to paste those two lines after the definitions in that function.  I doubt they should be in that function anyway; I threw them in there because I (like you) wanted an easy way to see if what you were trying to do was possible.

rac

On Oct 28, 2010, at 12:02 AM, kty1104 at gmail.com wrote:

> omg it works!!
> thank you!
> although I am satisfied with this method, 
> do you know the better way for it?
> 
> , Richard Cleis <rcleis at mac.com>님이 작성:
> > Insert the two lines below to see that what you want is possible, but I doubt such a quick hack is the right way to do it.
> > 
> > 
> > 
> > rac
> > 
> > 
> > 
> > On Oct 27, 2010, at 8:48 PM, kty1104 at gmail.com wrote:
> > 
> > 
> > 
> > > hello
> > 
> > > I finally circle the bitmap where I point by mouse
> > 
> > > but there are several problem
> > 
> > > 1. the circle filled with white color that I can't see bitmap through the circle
> > 
> > > 2. the drawn circle didn't erased after I point another coordinates
> > 
> > >
> > 
> > > could somebody give me an little advice?
> > 
> > >
> > 
> > > my code looks messy and not neat but
> > 
> > > I paste the code for make it easier to understand
> > 
> > >
> > 
> > >
> > 
> > > #lang scheme
> > 
> > > (require 2htdp/image
> > 
> > > racket/gui)
> > 
> > > (define chipset (make-object bitmap% "town.png" 'png))
> > 
> > > (define (check dc m)
> > 
> > 
> > 
> > 
> > 
> >  (send dc draw-bitmap chipset 0 0)
> > 
> >  (send dc set-brush "blue" 'transparent)
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > (define x (send m get-x))
> > 
> > > (define y (send m get-y))
> > 
> > > (send dc draw-ellipse (- x (modulo x 16)) (- y (modulo y 16)) 16 16))
> > 
> > > (define f (new frame% (label "map editor")))
> > 
> > > (define xymsg (new message% (label "nth so far") (parent f)))
> > 
> > > (define select%
> > 
> > > (class canvas%
> > 
> > > (override on-event on-paint)
> > 
> > > (define on-paint (λ () (send (send this get-dc) draw-bitmap chipset 0 0)))
> > 
> > > (define on-event (λ (m)
> > 
> > > (send xymsg set-label
> > 
> > > (string-append "x:"
> > 
> > > (number->string (send m get-x))
> > 
> > > " y:"
> > 
> > > (number->string (send m get-y))))
> > 
> > > (when (send m get-left-down) (check (send this get-dc) m))))
> > 
> > >
> > 
> > > (super-new )
> > 
> > > ))
> > 
> > > (new select% (parent f) (min-width (image-width chipset)) (min-height (image-height chipset)) )
> > 
> > > (send f show #t)_________________________________________________
> > 
> > > For list-related administrative tasks:
> > 
> > > http://lists.racket-lang.org/listinfo/users
> > 
> > 
> > 
> >



Posted on the users mailing list.