I'm trying to figure out this weird problem I've run in to.
I have a multidimensional array that is essentially a 2D matrix comprised of binary values. 1 represents an area that's filled, 0 is empty. I'm treating this as "pixel art" although the application is vastly different.
What I want to do is expand the array to fit a certain amount of ones (adding rows & columns, duplicating "pixels"), sort of when enlarging an image.
Here's what would be a crude example of what I'm working with:
$shape = array(
array(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0),
array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0),
array(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0),
array(0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0),
array(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0),
array(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0),
array(0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0),
array(0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0),
array(1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1),
array(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1),
);
Down the line the shapes will get trickier, but I'm using this as a test piece, however they will always be solid and binary just like this star.
Right now the fill value of this array is 135 (how many ones there are). Let's say I want to change the fill value to exactly 309, 2048 or 15. Is there a neat way to accomplish this in PHP while retaining the shape of the initial matrix?
To clarify, I don't want to enlarge the matrix by x amount of columns & rows, I want to specify exactly how many ones I want in the final matrix, if the match isn't 100% I'm fine with that, as long as I'm left with exactly the number of ones I specified.
I'm fooling around with pixel-art scaling algorithms, but can't quite wrap my head around how to deal with this problem.