Test for "within graphic"?
Jim Hurley
jhurley at infostations.com
Wed Mar 24 13:37:20 EST 2004
>
>Message: 4
>Date: Wed, 24 Mar 2004 09:35:58 -0600
>From: "Ken Ray" <kray at sonsothunder.com>
>Subject: RE: Test for "within graphic"?
>To: "'How to use Revolution'" <use-revolution at lists.runrev.com>
>Message-ID: <033f01c411b5$b77509b0$6601a8c0 at precision340>
>Content-Type: text/plain; charset="US-ASCII"
>
>Yes - use the within() function:
>
> if within(grc "Polygon","100,125") then
> -- etc.
> end if
>
>HTH,
>
>Ken Ray
>Sons of Thunder Software
>Email: kray at sonsothunder.com
>Web Site: http://www.sonsothunder.com/
>
Ken,
I was unaware of this use of "within" It opens up new possibilities
for a question that came up some time ago on the list, namely that
of detecting a collision between two polygons.
For example the following beeps when two polygons intersect:
local myName
on mouseUP
put "" into myName
end mouseUP
on mouseDown
put the name of me into myName
end mouseDown
on mouseMove x,y
if myname is empty then exit mouseMove
set the loc of me to x,y
put the points of grc "myPoly1" into myPolyPoints1
put the points of grc "myPoly2" into myPolyPoints2
repeat for each line tPoint in myPolyPoints1
if within(grc "myPoly2",tPoint) then beep
--The following line doesn't work
--if tPoint is within the rect of grc "myPoly2" then beep
end repeat
repeat for each line tPoint in myPolyPoints2
if within(grc "myPoly1",tPoint) then beep
end repeat
end mouseMove
Notice that
If tPoint is within the rect of grc "myPoly"
is not the same as
if within(grc "myPoly,tPoint)
although the docs says they should be.
I confess this is a bit confusing, since "put the rect of grc
"myPoly" yields the four rectangular points defining the rect of
"myPoly," and not the set of points which define the vertices.
Jim
More information about the use-livecode
mailing list