Perhaps against my better judgement, I decided to try to get graphics working in scheme. (MIT/GNU)
To get it started, I wrote
(define graphics-types (enumerate-graphics-types))
(define graphics (make-graphics-device (car graphics-types)))
which popped up a white window. Calling
(graphics-draw-point graphics .5 0)
gave the expected result, which was that a little black pixel appeared 3/4 of the way to the right of the window (vertically in the center). However, calling
(graphics-erase-point graphics .5 0)
did nothing. Furthermore, minimizing and restoring the window erased the point, but experimentation showed that minimizing always cleared the entire window.
Does anyone know what's going on?
The graphics-erase-point procedure in MIT Scheme works by changing the drawing mode to 0, calling graphics-draw-point, then changing the drawing mode back to whatever it was before. More information on the mechanics of MIT Scheme drawing modes can be found at MIT's drawing mode documentation
The bug appears to be in the graphics-bind-drawing-mode procedure, which is used in graphics-erase-point to change the drawing mode. The easiest solution is to redefine graphics-erase-point to use graphics-set-drawing-mode instead. The resulting code looks like this:
(define (graphics-erase-point device x y)
(graphics-set-drawing-mode device 0)
(graphics-draw-point device x y)
(graphics-set-drawing-mode device 15))
15 is the default drawing mode, which I've used for the sake of simplicity, but it is certainly possible to intelligently revert drawing modes (I leave that exercise for you).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With