[racket] Tweaking the graphical coordinate system

3 views
Skip to first unread message

Diogo F. S. Ramos

unread,
May 31, 2012, 1:33:03 AM5/31/12
to us...@racket-lang.org
While using The Racket Drawing Toolkit, is it possible to flip a dc%
vertically so the bottom left becomes (0, 0)?

I'm also using The Racket Graphical Interface Toolkit to create a
canvas% and grab its dc%, so flipping the canvas% is also a option.

By flipping I mean, the coordinate system is:

|
-+-------->
|
|
|
v

And I would like it to be:

^
|
|
|
-+------->
|

--
Diogo F. S. Ramos
____________________
Racket Users list:
http://lists.racket-lang.org/users

Matthew Flatt

unread,
May 31, 2012, 7:57:46 AM5/31/12
to Diogo F. S. Ramos, us...@racket-lang.org
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]))

(void
(new canvas%
[parent f]
[paint-callback
(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)
Reply all
Reply to author
Forward
0 new messages