Constrain Within Circle?

Roger Guay irog at mac.com
Sat Nov 5 14:10:57 EST 2005


Cool, Jim.  And, if you change just one line of your code in the  
mouseMove handler to

                                                                         
               "if   rr is not r then"

you get an object that is constrained to move on the circle of radius  
rr.  This is useful if you want to build a rotary knob for example.



Cheers, Roger


On Nov 5, 2005, at 10:00 AM, use-revolution-request at lists.runrev.com  
wrote:

> 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
>




More information about the use-livecode mailing list