Hi,
Its friday, and in local time the clock is 3.22pm, so my brain wont give me a solution, so i ask:
Im trying to write a function/algorithm in Actionscript 3.0 that gives me the most average positions of x number of positions along a path of y number of available positions.
Y is always larger than X of course.
The background is, I got a map, with for example 50 possible placements of objects (along a path). But i only got 32 objects to place along this path, but i want their placements to be as average/even along that path as possible. So that it for example won't be a big gap at the end. My avaiable positions are at the moment stored in an array with point values.
If you just do totalPos/wantedPos and floor it, it will be a "ugly" gap at the end, any ideas?
EDIT:
I wanted to add the function incase anyone else wants it:
function place (x : uint, y : uint ) : Array
{
var a : Array = new Array();
var s : Number = y / x;
var c : Number = 0;
for (var i : Number = 0; i<x; i++) {
c++;
var pos : Number = Math.round(i * s);
a.push(posArray[pos]);
}
return a;
}
Assumes you have an array posArray with the possible positions already...