Cowberry dessert cream
Cowberry Dessert Cream
(flash9player)-(start the show)

Points flying around a flat space and drawing lines between each other when getting close enough.

When each flying point is calculating their distance between all other points the code is getting slow. That’s because of too much calculation. There are a lots of unnecessary calculations going on. This code would run pretty well with 20 points, but I need more!

The thing is that we only should need to calculate distance between points that are close each other. Nothing more. To do this I imagined the stage in squares and gave every point a category variable that comes from their current position in stage full of squares. (I’ll explane the code in a simplest way possible)

// split the stage in squares
squares = 10
sqx = stageWidth / squares
sqy = stageHeigth / squares

point[i].spot = ( x / sqx ) + “” + ( y / sqy )

Now after this I can check if points have a same or “next to” value in their category variable. And pum! the code runs much faster. The Cowberry dessert cream have 60 points moving and interacting with other points and it looks beautyful!