use-revolution Digest, Vol 26, Issue 19
Malte Brill
revolution at derbrill.de
Sat Nov 5 07:51:00 EST 2005
This will allow to move anywhere inside the circle, but still only
constrains the loc of the object.
Also cleared up the circleCenter and radius handling a bit.
Cheers,
Malte
global x,y,myRadius
on mouseUp
set the uAllowDrag of me to false
end mouseUp
on mouseRelease
mouseUp
end mouseRelease
on mouseDown
put 100 into x
--xlocation of circleCenter
put 100 into y
--yLocation of circleCenter
put 80 into myRadius
--radius of the circle
set the uAllowDrag of me to true
end mouseDown
on mouseMove
if not the uAllowDrag of me then exit mouseMove
if distance(x,y,the mouseLoc)>80 then
set the loc of me to \
pointOnCircle(x,y,findangle(x,y,the mouseLoc) - 90,myRadius)
else
set the loc of me to the mouseloc
end if
end mouseMove
function distance
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 distance
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
if y2 is empty then
return "Error: Syntax is distance(x1,y1,x2,y2)"&cr&theValue
end if
put x1-x2 into oppositeLeg
put y1-y2 into adjacentLeg
put round(sqrt (oppositeLeg^2+adjacentLeg^2)) into hypotenuse
return hypotenuse
end distance
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
More information about the Use-livecode
mailing list