Closed zhaozhemin closed 4 years ago
You are missing the shape and size of the pen used to draw the line. The default pen is a 1x1 square (a single pixel). The matrix transform blows this up to a size of 198x198 so your line is drawn with a huge, square pen. If you want a "hair line" you can set the pen width to 0 otherwise try 1/198.
(require racket/draw)
(define bm (make-bitmap 200 200)) (define dc (new bitmap-dc% [bitmap bm])) (define pen (new pen% [width 1/198])) (send dc set-pen pen)
(send dc set-initial-matrix (vector 198.0 0.0 0.0 -198.0 0.0 200.0)) (send dc draw-line 0.0 0.0 1.0 1.0) bm
/Jens Axel
Den ons. 22. apr. 2020 kl. 17.48 skrev Zhao Min notifications@github.com:
It seems that instead of frame-coord-map, this implementation maps the points in the unit square to the actual output device by manipulating the transformation matrix. I played a little bit, but can't grasp how it's done.
Take this painter as an example:
(define line (vects->painter (list (make-vect 0 0) (make-vect 1 1))))
The transformation matrix right before it draws the line is #(198.0 0.0 0.0 -198.0 0.0 200.0). I verify the mapping by hand using the formula. It correctly maps '(0 0) to '(0 200), and '(1 1) to '(200 0). (I use #(200.0 0.0 0.0 -200.0 0.0 200.0) for easy calculation.)
But when I run the following code:
(define bm (make-bitmap 200 200)) (define dc (new bitmap-dc% [bitmap bm])) (send dc set-initial-matrix (vector 198.0 0.0 0.0 -198.0 0.0 200.0)) (send dc draw-line 0.0 0.0 1.0 1.0)
It just gives this picture
[image: untitled] https://user-images.githubusercontent.com/10150604/80001775-59fda000-84f1-11ea-9e46-d95c9c92386e.png
What am I missing?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sicp-lang/sicp/issues/33, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQXRNKVK4AMK5EGXP4C6DRN4GVDANCNFSM4MOJBUNA .
-- -- Jens Axel Søgaard
It works. Thank you very much.
Great it worked.
It seems that instead of
frame-coord-map
, this implementation maps the points in the unit square to the actual output device by manipulating the transformation matrix. I played a little bit, but can't grasp how it's done.Take this painter as an example:
The transformation matrix right before it draws the line is
#(198.0 0.0 0.0 -198.0 0.0 200.0)
. I verify the mapping by hand using the formula. It correctly maps'(0 0)
to'(0 200)
, and'(1 1)
to'(200 0)
. (I use#(200.0 0.0 0.0 -200.0 0.0 200.0)
for easy calculation.)But when I run the following code:
It just gives this picture
What am I missing?