Random movement of some little objects?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Random movement of some little objects?

Post by richmond62 » Wed Dec 30, 2020 1:01 pm

Parts of the graphical line which are straight lines are described bei two points only regardless the distance.
unfortunately

Code: Select all

move to the points of graphic "XXX"
will do EXACTLY WHAT IT SAYS ON THE PACKET . . . :?

So: my experience is that IFF you want to animate something along a curse you need to generate a curve with a large
number of points very close to each other to avoid any visible jerkiness.

-
BUZZY.jpg
-
This is a little stack I just knocked up that generates a half circle curve and then sends a 'bee' along it: from this you should
be able to see what I am getting at.

Of course you can make the graphic curve invisible and so on. 8)
Attachments
BUZZY.livecode.zip
Here's the stack.
(22.66 KiB) Downloaded 245 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Wed Dec 30, 2020 3:12 pm

Hi.

It is true that a random string of points, generated by script, will appear jerky for the reasons you mentioned. The random changes in direction, followed by randomly long distances to the next point in the list, are what we perceive as jerkiness.

So you need to generate a random list of points where each new point is only a little bit different from the previous. But this will not "move" the object too far, being essentially a "random walk" exercise. The object will move smoothly and randomly, but very near its starting point.

That list has to have a "sense" of direction, in that its elements are still random, but retain a directional trend even as they continue their randomness. This can easily be done.

The points of a curve, however convoluted, already do that, since its points are strung out in a directionally sequential fashion as the curve is physically drawn. One cannot draw a curve in any other way.

So my question is this. Apart from the simple joy of writing a curve-like list of random points, why bother, since a graphic already does that, can be hidden, and works a treat?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Random movement of some little objects?

Post by richmond62 » Wed Dec 30, 2020 3:44 pm

But this will not "move" the object too far
?

You can have a curve with thousands of points that carries an object as far as you like.

Mind you, generating anything beyond rather obvious sections and cycles generated using sine and cosine combinations
will prove a grind that is probably not worth the effort.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Wed Dec 30, 2020 5:20 pm

?
A random walk is one where an object is moved randomly, point by point. When this is run, the object stays very near its starting position, since each change in position ought never to produce a reasonable travel in any particular direction. This is a law of averages thing; it could happen, it is just not likely.

I mentioned this when I spoke about small random changes in a list of points, in the context of reducing jerkiness. Pure random will not do. You have to have a "goal", groupings of points that have a "direction", randomly sprinkled throughout the list, in order to get the object to trace a reasonable visual path. And all these groups have to follow each other, or you get a "jerk" between the groups.

So the generation of a random list, for this purpose, has to have a certain amount of order to it.

I am a fan of following a graphic. The way they are drawn produces the type of point list the OP is after.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Random movement of some little objects?

Post by jacque » Wed Dec 30, 2020 6:04 pm

You might get better results if you let LC do it for the entire graphic rather than trying to script every segment of the move.

Code: Select all

move img x to the points of grc y in 0.5 seconds without waiting 
The engine should smooth out the hops this way. You're right that only the minimum number of points are used to define a graphic.

You can use your variable's list instead of "the points of grc y" but it isn't necessary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Wed Dec 30, 2020 11:14 pm

Jacque.

Draw a graphic and let the object move to its points.

This is the "correct" solution to the original OP issue. Look back in this thread a bit and you will see. The discussion at this point is off in the weeds, talking about generating a list of points under script control, instead of letting a graphic do the walking. Making such a list is easy. Making it work like a list generated by the drawing of a curve requires more effort. It is not, in my opinion, apart from the pleasure in doing so, er, worth doing so.

randomMover.livecode.zip
(2.97 KiB) Downloaded 227 times
Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Random movement of some little objects?

Post by jacque » Thu Dec 31, 2020 3:23 am

@Craig, I've been sort of half following this thread. My intention was just to agree with you. Scripting the hops won't ever be as smooth as letting the engine do it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Thu Dec 31, 2020 3:54 am

Jacque.

Hi.

I will stop work just to fool around with LC, to create, say, a random yet "smooth" list of points solely from a handler. It helps, of course, that I do not have to report to anyone.

Anyway, I laid out the method to create such a list, but I don't think I will pursue it.

Craig

Francesco77
Posts: 40
Joined: Mon Nov 16, 2020 8:16 pm

Re: Random movement of some little objects?

Post by Francesco77 » Thu Dec 31, 2020 9:10 am

Thank you all for your help and suggestions.

One reason I tried using a list of points instead of letting LC do the work was that it is possible to change the direction of the movement this way.
I worked through the list of points in reverse order and flipped the image of the moved objects each time the direction changed.

Maybe this is also possible when LC moves the objects along the curves but I did not find out how to do it :oops:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Thu Dec 31, 2020 3:39 pm

Hi.

Do you need to control the movement while it is running? Otherwise, if you have been following this thread, you see that, although possible to create a "smooth" list of points, such a task requires effort well beyond the simple random point generator I suggested early on. That post was short-sighted in the context of your needs.

I was ready to set this aside. But if you have good reason to pursue it, let me know, and we might just keep it going.

Craig

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Random movement of some little objects?

Post by Newbie4 » Thu Dec 31, 2020 5:54 pm

Francesco77 wrote:
Thu Dec 31, 2020 9:10 am
Thank you all for your help and suggestions.

One reason I tried using a list of points instead of letting LC do the work was that it is possible to change the direction of the movement this way.
I worked through the list of points in reverse order and flipped the image of the moved objects each time the direction changed.

Maybe this is also possible when LC moves the objects along the curves but I did not find out how to do it :oops:
Instead of using a list of points, draw the path using the freehand tool

from https://sites.google.com/a/pgcps.org/li ... -and-paths
4. Moving it along a Set Path - You can "program" objects to move along a set path.
You draw a path with the "Freehand" tool from the tools Palette (let's call it "path" - name it in the property inspector), then you add the line (or a similar one):

Code: Select all

move the button "box"  to the points of the graphic "path"  in 5 secs
(See the file MovingAlongAPath for a crude screenshot of how to do it https://docs.google.com/a/pgcps.org/vie ... jM1OTRiOTE)

You can set the graphic "path" not visible which makes the game more interesting
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Random movement of some little objects?

Post by richmond62 » Thu Dec 31, 2020 6:40 pm

You draw a path with the "Freehand" tool from the tools Palette
Indeed you can: however, unless you have an extremely jittery hand, there will be very few points along your path.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Thu Dec 31, 2020 6:51 pm

Newbie, have you read this thread?

Craig

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Random movement of some little objects?

Post by Newbie4 » Thu Dec 31, 2020 7:57 pm

Yes. The original post described it as a little game for kids. The poster was looking for an easier way to create random moving figures. He/she was even willing to just find or buy such scripts. I was just reiterating the easiest way without the having to create complex equations. I was reinforcing what you just said.

Too bad there isn't a way to control the number of points generated in a graphic (larger sampling) or a "smooth" function. At best, you can control the speed to hide the jaggedness of the graphic.

Thanks
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Random movement of some little objects?

Post by dunbarx » Thu Dec 31, 2020 10:28 pm

I suppose you could go through the list and insert intermediate points that "fit" between them. But a line graph does such a good job in its own right that I do not see the need.

Craig

Post Reply