# Constrain Within Circle?

Malte Brill revolution at derbrill.de
Sat Nov 5 03:44:17 EST 2005

```Hi Scott,

I´m not sharing too much of a secret here, so hereWeGo . :-)
(The param checking might be unneccesary for you. I just copied and

Hope that helps,

Malte

on mouseUp
set the uAllowDrag of me to false
end mouseUp

on mouseRelease
mouseUp
end mouseRelease

on mouseDown
set the uAllowDrag of me to true
end mouseDown

on mouseMove
if not the uAllowDrag of me then exit mouseMove
put 100 into x
--xlocation of circlecenter
put 100 into y
--ylocation of circlecenter
set the loc of the target to pointOnCircle(x,y,findangle(x,y, the
end mouseMove

Function findAngle
repeat with i=1 to paramcount()
if i<paramcount() then
put param(i)&"," after theValue
else
put param(i) after theValue
end if
end repeat

repeat with i=1 to the number of items of theValue
if item i of theValue is not a number then
return "Error: All Parameters must be numbers!"
exit findAngle
exit repeat
end if
end repeat
put item 1 of theValue into x1
put item 2 of theValue into y1
put item 3 of theValue into x2
put item 4 of theValue into y2
put abs(x1-x2) into oppositeLeg
put alpha*180/pi into alpha
else
put 90 into alpha
end if
switch
case x1<=x2 and y1>=y2
put alpha into foundAngle
break
case x1<=x2 and y1<=y2
put 180-alpha into foundAngle
break
case x1>=x2 and y1<=y2
put 180+alpha into foundAngle
break
case x1>=x2 and y1>=y2
put 360-alpha into foundAngle
break
end switch
return round(foundangle)
end findAngle

function pointOnCircle

repeat with i=1 to paramcount()
if i<paramcount() then
put param(i)&"," after theValue
else
put param(i) after theValue
end if
end repeat

repeat with i=1 to the number of items of theValue
if item i of theValue is not a number then
return "Error: All Parameters must be numbers!"
exit pointOnCircle
exit repeat
end if
end repeat

put item 1 of theValue into centerX
put item 2 of theValue into centerY
put item 3 of theValue into isAngle
put item 4 of theValue into isRadius