[racket] rotate an image using 2htdp/image
Here's a simple example that illustrates one initially surprising behavior
with rotate. This wiggling really confounded me the first time I saw it.
#lang scheme
(require 2htdp/image)
(require 2htdp/universe)
(define BACKGROUND (rectangle 100 100 "outline" "white"))
(define TRI (triangle 35 "solid" "blue"))
(define (render ang)
(place-image (rotate ang TRI) 20 20 BACKGROUND))
(define (tock ang)
(modulo (+ ang 10) 360))
(big-bang 0 (on-draw render) (on-tick tock))
This may only be tangentially related to what you're focusing on now,
Matthew. But it's important to realize that the bounding box of an
equilateral triangle is not a square but a rectangle. Also, take a look at
the examples in the documentation for rotate...note how the horizontal width
and vertical height of the ellipse's bounding box depend on how much you
rotated it. So to center such an image in the screen takes extra work. By
placing what you want to rotate inside of a white circle, you can establish
a more consistent bounding rectangle--a constant square.
I find it very handy to start by using outlined or colored circles as
backgrounds for any rotating sprites and for any parts of images that use
rotate to animate. The colors and outlines can be dropped later.
-Paul
> -----Original Message-----
> From: users-bounces at racket-lang.org [mailto:users-bounces at racket-lang.org]
> On Behalf Of Robby Findler
> Sent: Monday, July 19, 2010 5:52 PM
> To: Eugene Wallingford
> Cc: users at racket-lang.org
> Subject: Re: [racket] rotate an image using 2htdp/image
>
> Well, the 2htdp/image library does not work like that. If you overlay
> and the rotate then your background will be roated. If you rotate and
> then overlay the you may place things in different (relative)
> positions but you still don't get any different behavior by rotating
> around different points.
>
> Maybe our original poster can supply a small example and then we'll be
> able to get at the real question?
>
> Robby
>
> On Monday, July 19, 2010, Eugene Wallingford <wallingf at cs.uni.edu> wrote:
> >
> >> > Just want to clear up things....the how can adjust the pinhole or the
> >> > rotation center?
> >>
> >> There is no pinhole. My earlier reply was trying to tell you that this
> >> question does not make sense.
> >
> > Perhaps Matthew is concerned not so much with the
> > resulting orientation of the image as with its
> > resulting location in the original field. If I
> > rotate an image 180 degrees about its upper
> > leftmost corner, most or all of it may be out
> > the original view.
> >
> > ---- Eugene
> > _________________________________________________
> > For list-related administrative tasks:
> > http://lists.racket-lang.org/listinfo/users
> >
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users