vendredi 28 juillet 2017

Random generation of X and Y coordinates in javascript for random motion

I am looking for a way to generate a stream of x and y coordinates within a bounding region, for example, a 600x600 box. This stream of data is for a model which contains the position of the element that it represents. I do not want to use a Jquery animate method as this manipulates the top and left the property of the elements usually which goes against what I am trying to do where a model represents the position.

Things like jQuery methods provide the movement I like, however, as I said I want it in x and y coordinates.

One method I thought of was selecting a random point within the region and calculating the line between the current point and the random point and then slowly stepping along that line, there are multiple elements to manage so this should have to be done for each with the appearance of it happening at the same time.

The issue is I can't think of how to do this.




Aucun commentaire:

Enregistrer un commentaire