-1
我想繪製一個使用PHP的十六進制。我一直在努力遵循http://www.redblobgames.com/grids/hexagons/的手冊,支持自己使用leland hex代類(https://github.com/pushcx/leland/blob/master/class_hex_image.php)。如何在PHP中繪製扁平十六進制(標題)圖像?
不幸我的「十六進制」看起來是這樣的:
能否請您指點我究竟做錯了,或者告訴我怎樣才能建立一個適當的十六進制?
在我看來,那功能,抓住六角角落無法正常工作:
function hex_corners($center, $size)
{
$points = array();
for($i=0; $i <= 5; $i++)
{
$deg = 60 * $i; // Oblicz kąt, w którym znajduje sie róg hexu
$rad = pi()/180 * $deg; // Przelicz kąt na radiany
$points[$i] = array_push($points, $center['x'] + $this->size/2 * cos($rad), $center['y'] + $this->size/2 * sin($rad));
}
return($points);
}
,但我試圖模仿http://www.redblobgames.com/grids/hexagons/說明書中所描述的:
function hex_corner(center, size, i):
var angle_deg = 60 * i
var angle_rad = PI/180 * angle_deg
return Point(center.x + size * cos(angle_rad),
center.y + size * sin(angle_rad))
我現在用的是以下抽獎功能:
public function hex_draw($x, $y)
{
$this->hex = imagecreatetruecolor ($this->size , $this->size);
$center['x'] = $this->size/2;
$center['y'] = $this->size/2;
$blue = imagecolorallocate($this->hex, 0, 0, 255);
// Get points
$points = $this->hex_corners($center, $this->size);
//die($print_r($points);
imagefilledpolygon($this->hex, $points, count($points)/2, $blue);
// flush image
header('Content-type: image/png');
imagepng($this->hex);
imagedestroy($this->hex);
}