[racket] erasing a line?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Jun 30 20:20:01 EDT 2011

On Fri, Jul 1, 2011 at 12:09 AM, John Riedl <riedl at cs.umn.edu> wrote:
> Hello.  I've been developing a simple turtle graphics package to let
> my students play with drawing simple shapes, such as fractals.  I've
> been struggling with an approach that is efficient for large and
> complex drawings.  I've tried two approaches:
>
> 1. Keep a list of the lines that have been drawn as the model.  After
> each turtle move refresh-now to update the view by redrawing all the
> lines.  This approach works great, but slows down as the number of
> lines grows large, such as for complex fractals.
>
> 2. Keep a backing bitmap into which the lines are drawn as the model.
> After each turtle move refresh-now to copy the bitmap onto the canvas.
>  This approach also works great, but is always slow for large
> canvases.  (At least it doesn't get slower over time!)
>
> In the past I've used drawing packages -- including PLT! -- that had
> an xor operator that worked as one would expect, which made the
> solution easy: just draw with xor, and then redraw with xor to erase.
> The 'xor style in Racket is the same as 'solid, so that doesn't work.

Yes, there is no 'xor anymore. The underlying GUI we use (cairo)
doesn't support it anymore.

> In the past I've used drawing packages that let me set the region to
> be redrawn by the paint routine, which then allows for much more
> efficient updating.  I don't think that would speed up approach (1),
> since all the lines would have to be drawn to compute the clipping,
> but it might make approach (2) fast.  I don't know how to do that in
> Racket.

I believe you can do that by just drawing directly into a canvas%
object's dc the updated region (and, at the same time, draw into your
backing bitmap to handle refresh requests). I'm not positive if that
still works in the 5.1 world but I think that it does. the editor
classes use this technique; when you're typing in drracket, they only
redraw the online line that you're typing on, unless your edit spans
multiple lines.

> I can easily redraw the turtle with the background color, but that
> erases some of the lines, which looks ugly.
>
> I could instead just copy the part of the bitmap that represents where
> the turtle used to be to the canvas, effectively erasing it.  With
> this approach, I'd quit using refresh-now, and instead just draw
> directly to the canvas.  This approach seems a little less elegant --
> the model has to stay around for when refresh is actually needed, so
> the lines will be drawn twice -- and I'm not sure how efficient it is
> to copy part of a bitmap onto a canvas.
>
> Advice?
>
> Thanks,
> John
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



Posted on the users mailing list.