Message: 11
Date: Fri, 04 Nov 2005 22:12:40 -0800
From: Scott Rossi <[EMAIL PROTECTED]>
Subject: Constrain Within Circle?
To: How to use Revolution <use-revolution@lists.runrev.com>
Message-ID: <[EMAIL PROTECTED]>
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
_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution