Cool, Jim. And, if you change just one line of your code in the mouseMove handler to

"if rr is not r then"

you get an object that is constrained to move on the circle of radius rr. This is useful if you want to build a rotary knob for example.



Cheers, Roger


On Nov 5, 2005, at 10:00 AM, [EMAIL PROTECTED] wrote:

The following script should keep the contol it is in to the inside of
a circle of radius r. The variable rr is the distance from the mouse
to the center of the circle at x0,y0. It uses a simple
proportionality in similar triangles.

local myName,x0,y0,r

on mouseDown
   put the name of me into myName
   put round((the width of this card)/2)  into x0
   put round((the height of this card)/2) into y0
   put 200 into r
end mouseDown

on mouseUP
   put  "" into myName
end mouseUP

on mouseLeave
   mouseUP
end mouseLeave


on mouseMove u,v
   if myName is "" then exit mouseMove
   put sqrt((u-x0)^2 + (v-y0)^2) into rr
   if   rr >r then
     set the loc of me to x0+(u-x0)*r/rr, y0+(v-y0)*r/rr
   else  set the loc of me to u,v
end mouseMove

Jim


_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to