Pattern / racket: canvas manipulation

1) As the name says, the objects that I draw disappear when I resize the window, but the rectangle remains as it is.

2) Origin starts from the upper left corner, but I want it to be in the lower left corner.

3) I could not find any scaling functions, except in the plot library, so if I want to implement such a thing, one option will be "scaled" by drawing large objects and updating the content instead?

(define top-frame (new frame%
                         [label "KR"]
                         [width 500]
                         [height 500]))
;Make a frame by instantiating the frame% class

(define image (pict->bitmap (rectangle 50 50)))

(define canvas (new canvas%
                    [parent top-frame]
                    [paint-callback (lambda (canvas dc)
                                      (send dc draw-bitmap image 0 0))]))

(define drawer (send canvas get-dc))

(send top-frame show #t)
; Show the frame by calling its show method

(define (draw-object x)
  (sleep/yield 0.1)
  (case (first x) 
    [("LINE") (send drawer draw-line
                    (second x) (third x)
                    (fourth x) (fifth x))]
    [("CIRCLE") (send drawer draw-bitmap (pict->bitmap (circle (round (fourth x)))) (round (second x)) (round (third x)))]
    [("POINT") (send drawer draw-point (round (second x)) (round (third x)))]
    [else "Not drawing anything!"]))

(draw-object (find-specific-values (third list-of-objects)))
(map draw-object (map find-specific-values list-of-objects))
+4
source share
1 answer

ad 1) "... , , ..." . , GUI Racket paint. : , . paint. . : fooobar.com/questions/1153604/...

ad 2) . . Set-transform dc <% > . - :

(send dc set-transformation 
        (vector (trans->vector t)
                0   0 ; x and y origin
                1  -1 ; x and y scale
                0)))

-1 y- y. , .

ad 3) x y, .      1/2 -1/2.

+4
source

All Articles