Constrain Within Circle?
jhurley at infostations.com
Sat Nov 5 07:59:43 CST 2005
>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,
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.
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
put "" into myName
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
More information about the use-livecode