I am trying to create a wheel of fortune type game. Basically, it involves spinning an image like until it slows down and lands on a prize.
The problem is that I want to dynamically create the wheel. In some cases I might have only 5 "pieces" and in other cases I might have as many as 10 "pieces". So I need to find a way, using PHP, to build an image like this:
Out of several rectangular images.
- Is there an easy way to do this?
- If not, what PHP kit should I use to build this?
UPDATE
I am now able to create the pie with the slices:
$saveImage = 'image.png';
if (file_exists($saveImage)) {
unlink($saveImage);
}
$height = $width = 400;
// 1. Create a blank canvas image with transparent circle
$image = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($image, 0, 0, 0);
$col_ellipse = imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $bg);
imagefilledellipse($image, ($width / 2), ($height / 2), $width, $height, $col_ellipse);
// 3. Divide image into slices
$numberOfSlices = sizeof($images);
$black = imagecolorallocate($image, 0, 0, 0);
$sliceDegrees = 360 / $numberOfSlices;
$first = true;
$radius = 0.5 * $width;
// start point is always the middle
$startX = $width / 2;
$startY = $height / 2;
$points = array();
for ($i = 0 ; $i < $numberOfSlices; $i++)
{
$angle = $i * ($sliceDegrees);
$endX = $radius * cos(deg2rad($angle)) + $radius;
$endY = $radius * sin(deg2rad($angle)) + $radius;
$points[] = array (
$endX, $endY
);
imageline(
$image,
$startX, $startY,
$endX , $endY,
//150, 150 + ($i * 10),
$black
);
}
The remaining problem is getting the image to fit in on the pizza slice. So I need to mask the image over that portion.