Constrain Within Circle?
Jim Hurley
jhurley at infostations.com
Sat Nov 5 08:59:43 EST 2005
>
>Message: 11
>Date: Fri, 04 Nov 2005 22:12:40 -0800
>From: Scott Rossi <scott at tactilemedia.com>
>Subject: Constrain Within Circle?
>To: How to use Revolution <use-revolution at lists.runrev.com>
>Message-ID: <BF918D58.24549%scott at tactilemedia.com>
>Content-Type: text/plain; charset="US-ASCII"
>
>Anyone have a formula to constrain object dragging within a circular region?
>
>I'm guessing something like Arcade Engine has this in it, but I really only
>need this one function.
>
>Thanks & Regards,
>
>Scott Rossi
Scott,
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
More information about the use-livecode
mailing list