[racket] Tweaking the graphical coordinate system

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu May 31 07:57:46 EDT 2012

At Thu, 31 May 2012 02:33:03 -0300, Diogo F. S. Ramos wrote:
> While using The Racket Drawing Toolkit, is it possible to flip a dc%
> vertically so the bottom left becomes (0, 0)?

The easiest way is to use `translate' and then `scale' with a negative
value for the y-direction.


#lang racket/gui

(define f (new frame%
               [label "Upside-Down"]
               [width 300]
               [height 300]))

 (new canvas%
      [parent f]
       (lambda (c dc)
         (define-values (w h) (send dc get-size))
         (define t (send dc get-transformation))
         (send dc translate 0 h)
         (send dc scale 1 -1)
         (send dc set-font (make-font #:size 32))
         (send dc draw-text "Hello" 0 0)
         (send dc set-transformation t))]))

(send f show #t)

Posted on the users mailing list.