[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Rotate image around another point?
Well, no.
I'm looking for a way to rotate the imagedata (like
pygame.transform.rotate(...)) but your example rotates the image
location. Right?
/John
tor 2007-04-19 klockan 10:36 +0200 skrev altern:
> hi john
>
> John Eriksson(e)k dio:
> > Hi,
> >
> > The rotate function in the transform module rotates an image about its
> > center. But what if I want to use another point?
> >
> > Is there another solution than to modify the size of the image to change
> > its center point?
>
> I think something like this should do what you are looking for.
>
> from math import *
>
> def rotPoint(point, axis, ang):
> """ Orbit. calcs the new loc for a point that rotates a given num
> of degrees around an axis point,
> +clockwise, -anticlockwise -> tuple x,y
> """
> x, y = point[0] - axis[0], point[1] - axis[1]
> radius = sqrt(x*x + y*y) # get the distance between points
>
> RAng = radians(ang) # convert ang to radians.
>
> h = axis[0] + ( radius * cos(RAng) )
> v = axis[1] + ( radius * sin(RAng) )
>
> return h, v
>
>
> myimage.center = rotPoint(myimage.center, (300,300), 45)
>
> this line should rotate myimage.center around point (300,300) by 45 degrees
>
>
> > Best Regards
> > /John Eriksson
> >
> >