[racket] erasing a line?
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.
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 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