Rotate around Center of Mass

BNig niggemann at uni-wh.de
Mon Jan 9 16:58:19 EST 2012


Hi Mark,

first thanks to Jim Hurley for his solution to turn the image around an
arbitrary point. As always I would never have figured it out.

This code is a slight adaption of Jim's code so you can put it into the
script of an image and click on the image and the image will turn around the
clickLoc.

You can also send the image the command turnAroundPoint and a parameter with
the coordinates of a point

turnAroundPoint pNewXY 

----------------------------------
on mouseUp
   put the clickLoc into tClick
   turnAroundPoint tClick
end mouseUp 

on turnAroundPoint pClick
   put pClick into tClick
   set the angle of me to 0 
   put the loc of me into myLoc 
   put the rect of me into tImgRect
   
   --Set the coor of the rotation Pt 
   put item 1 of tClick into x0 
   put item 2 of tClick into y0 
   
   --Get the loc of the image 
   put item 1 of myLoc into xC 
   put item 2 of myLoc into yC 
   
   --Get the distance between the roation pt and the image center 
   put sqrt ( (xC - x0 )^2 + (yC - y0)^2 )  into L 
   
   --Get the angle of the line from the rotation center to the image center 
   put atan2(yC-y0, xC-x0) *180/pi into phi0 
   
   put 0 into tAngle 
   
   repeat with i = 0  to 360 step 5 -- adjust stepsize to control speed 
      lock screen 
      set the angle of me to i 
      put phi0 - i into phi 
      set the loc of me to (x0 + L * cos(phi*pi/180)), (y0 + L *
sin(phi*pi/180)) 
      unlock screen 
      wait 5 millisec with messages --or whatever 
   end repeat 
   set the angle of me  to 0
   set the rect of me to tImgRect
end turnAroundPoint
------------------------------------------------

Kind regards

Bernd

--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Rotate-around-Center-of-Mass-tp4273701p4280217.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list