randomly position objects on-screen

Chris Sheffield cmsheffield at icloud.com
Fri May 31 13:45:59 CDT 2013


Roger,

Thank you. This works well.

I had to tweak it a bit to use the bottom of my graphic instead of the height, and that seems to position the controls a little better within my defined area. Then I just added some intersect checking and it seems to be working quite nicely.

Thanks again,
Chris


On May 31, 2013, at 12:06 PM, Roger Guay <irog at mac.com> wrote:

> Hi Chris,
> 
> I believe this will do it for you:
> 
> on placeBtnRandom pbtnName
>   put the width of btn pbtnName into bW
>   put the height of btn pbtnName into bH
>   put the width of this stack into sW
>   put the height of this stack into sH
>   put random(sW-bW) into tX
>   put random(sH-bH) into tY
>   set the loc of btn pbtnName to bW/2+ tX, bH/2 - tY  
> end placeBtnRandom
> 
> Regards,
> Roger
> 
> On May 31, 2013, at 10:49 AM, Chris Sheffield <cmsheffield at icloud.com> wrote:
> 
>> Okay, I figure someone out there has probably done this before, so I thought I'd ask here before I dive in to the deep end (or go off the deep end, whichever comes first).
>> 
>> Given a rectangular area (in this case a graphic object), I need to randomly position three controls (in this case Scott's tmControl buttons (groups)), within that area. It's not a huge area to work with, but the controls are not too big. The conditions are that the controls cannot intersect (overlap) and they have to be completely visible within the given area (not partially off-screen).
>> 
>> Any takers?
>> 
>> Thanks,
>> Chris
>> 
>> 
>> --
>> Chris Sheffield
>> Read Naturally, Inc.
>> www.readnaturally.com
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list