I'm looking for a way to get the cells based on a N range. But no luck.
I'm converting Row Column offset to Cube Coordinate system QR -> XYZ
$range = 1;
for ($dx = -$range; $dx <= $range; $dx++)
{
for ($dy = max(-$range, -$dx - $range); $dy <= min($range, -$dx + $range); $dy++)
{
$dz = -$dx-$dy;
$points = $hexagon->cube_to_oddq(array($dx,$dy,$dz));
$x = $hexagon->ver + $points[0] * $hexagon->size * 1.5;
$y = $hexagon->height + $points[1] * $hexagon->height + ( ($points[0]%2) * ( $hexagon->height / 2 ) );
$points = $hexagon->drawHex($x,$y, true);
$pointss = array();
foreach($points as $p) {
$pointss[] = $p[0];
$pointss[] = $p[1];
}
imagefilledpolygon ( $png_image , $pointss , 6 , $black );
}
}
Result: Inside every hex cell (First line is QR coordinate) (Second line is XYZ converted coordinate)
Any advice what I'm doing wrong?
Update:
As requested, the Oddq (Q,R) to Cube conversion XYZ
$i = $hex[0] = ROW
$j = $hex[2] = COLUMN
public function oddq_to_cube($hex){
$hex[2] = $hex[1];
$x = $hex[2];
$z = $hex[0] - ($hex[2] - ($hex[2]&1)) / 2;
$y = -$x-$z;
return array($x, $y, $z);
}
$curr_cube = $hexagon->oddq_to_cube(array($i,$j));
oddq_to_cube
while the original question only usedcube_to_oddq
. I'm also confused whether your variables$x
and$y
are in (X, Y, Z) as cubical coordinates or x, y as screen coordinates, as well as the intended behavior ordrawHex
andimageFilledPolygon
. \$\endgroup\$