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
pasted from ArcadeEngine)
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
put 80 into myRadius
--radius of the circle
set the loc of the target to pointOnCircle(x,y,findangle(x,y, the
mouseLoc)-90,myRadius)
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 abs(y1-y2) into adjacentLeg
if adjacentLeg<>0 then
put atan(oppositeleg/adjacentLeg) into alpha
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
put centerX+cos(isAngle*pi/180)*isRadius into isNewX
put centerY+sin(isAngle*pi/180)*isRadius into isNewY
return round(isNewX),round(isNewY)
end pointOnCircle
----
ArcadeEngine - prepare to WOW your audience within minutes
http://www.runrev.com/section/revselect/arcadeengine
http://www.derbrill.com/arcadeengine/forum
More information about the Use-livecode
mailing list