I am creating a small snake game in a racket and I am trying to show the boundaries.
I defined some constants:
(define WIDTH 500) (define HEIGHT 500) (define BLK_SIZE 10)
therefore, the entire block is a square of 50 pixels.
I created frame%
(define frame (new (class frame% (define/augment (on-close) (send timer stop) (printf "ending...\n")) (super-new)) [label "Snake"] [width WIDTH] [height HEIGHT]))
and canvas%
(define game-canvas% (class canvas% (define/override (on-char e) (case (send e get-key-code) [(left) (unless (eq? last-dir 'right) (set! dir 'left))] [(right) (unless (eq? last-dir 'left) (set! dir 'right))] [(up) (unless (eq? last-dir 'down) (set! dir 'up))] [(down) (unless (eq? last-dir 'up) (set! dir 'down))] [else (void)])) (super-new))) ;... (define game-canvas (new game-canvas% (parent frame)))
I defined the border:
(define (create-border) (let ( [nbr-block-x (/ WIDTH BLK_SIZE)] [nbr-block-y (/ HEIGHT BLK_SIZE)]) (append (for/list ([x (in-range nbr-block-x)]) (make-cell x 0)) (for/list ([x (in-range nbr-block-x)]) (make-cell x (sub1 nbr-block-x))) (for/list ([y (in-range nbr-block-y)]) (make-cell 0 y)) (for/list ([y (in-range nbr-block-y)]) (make-cell (sub1 nbr-block-y) y))))) (define borders (create-border))
And finally, I draw the borders:
(define-struct cell (xy)) (define (real-world-coordinate elem) (make-cell (* BLK_SIZE (cell-x elem)) (* BLK_SIZE (cell-y elem)))) (define (draw-list-of-square! dc square-list) (for-each (lambda (elem) (send dc draw-rectangle (cell-x (real-world-coordinate elem)) (cell-y (real-world-coordinate elem)) BLK_SIZE BLK_SIZE)) square-list))
With this code, I see no boundaries in my window. This is the result of the code (without resizing the frame):

As you can see, the right and bottom borders are outside my frame.
Since I am drawing a block from 0 to (sub1 nbr-block-x) (49) (in pixel 490), the borders should appear in my frame.
I checked frame document% and canvas%. Canvas% defines the fields that are set to 0 and frame% defines the border and spacing that are also set to 0.