|
|
imagearc (PHP 3, PHP 4, PHP 5) imagearc -- Draws an arc Описаниеbool imagearc ( resource image, int cx, int cy, int width, int height, int start, int end, int color )
imagearc() draws an arc of circle centered at the given
coordinates.
Список параметров
imageAn image resource, returned by one of the image creation functions,
such as imagecreatetruecolor(). cx
x-coordinate of the center
cy
y-coordinate of the center
width
The arc width
height
The arc height
start
The arc start angle, in degrees.
end
The arc end angle, in degrees.
0° is located at the three-o'clock position, and the arc is drawn
clockwise.
color
A color identifier created with
imagecolorallocate()
Возвращаемые значения
Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.
Примеры
Пример 1. Drawing a circle with imagearc() |
<?php
$img = imagecreatetruecolor(200, 200);
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
imagearc($img, 100, 100, 200, 200, 0, 360, $white);
imagearc($img, 100, 100, 150, 150, 25, 155, $red);
imagearc($img, 60, 75, 50, 50, 0, 360, $green);
imagearc($img, 140, 75, 50, 50, 0, 360, $blue);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
|
Результатом выполнения данного примера
будет что-то подобное: 
|
mojiro at awmn dot net
13-Dec-2005 12:28
A previous for the Rotated (Filled)Ellipse note from(nojer2 at yahoo dot com, 02-Apr-2001 12:06) has a mistake, at the second arc. Replace them with the following listing.
if ($filled) {
triangle($im, $cx, $cy, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
triangle($im, $cx, $cy, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
} else {
imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
imageline($im, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
}
ruturaj_v at yahoo dot com
17-May-2004 06:32
this is another piechart eg. very simple ...
<?php
global $deg;
function get_polar($xrel, $yrel, $ang, $radius) {
$i = $ang;
$ang = ($ang * pi())/ 180;
$ix = abs($radius*cos($ang));
$iy = abs($radius*sin($ang));
if ($i>=0 && $i<=90) {
$ix = $xrel + $ix;
$iy = $yrel - $iy;
}
if ($i>90 && $i<=180) {
$ix = $xrel - $ix;
$iy = $yrel - $iy;
}
if ($i>180 && $i<=270) {
$ix = $xrel - $ix;
$iy = $yrel + $iy;
}
if ($i>270 && $i<=360) {
$ix = $xrel + $ix;
$iy = $yrel + $iy;
}
$ix = floor($ix);
$iy = floor($iy);
$returnvals = array (
'x1' => $xrel,
'y1' => $yrel,
'x2' => $ix,
'y2' => $iy
);
return $returnvals;
}
function get_degtotal($degindex)
{
global $deg;
if ($degindex == 0 ) {
return ( $deg[$degindex] );
}
else {
return ( $deg[$degindex] + get_degtotal($degindex-1) );
}
}
$im = imagecreate (400, 400);
$w = imagecolorallocate ($im, 255, 255, 255);
$black = imagecolorallocate ($im, 0, 0, 0);
$red = imagecolorallocate ($im, 255, 0, 0);
$green = imagecolorallocate ($im, 0, 180, 0);
$randcolor[0] = imagecolorallocate($im, 243, 54, 163);
$randcolor[1] = imagecolorallocate($im, 179, 51, 247);
$randcolor[2] = imagecolorallocate($im, 103, 48, 250);
$randcolor[3] = imagecolorallocate($im, 53, 145, 244);
$randcolor[4] = imagecolorallocate($im, 54, 243, 243);
$randcolor[5] = imagecolorallocate($im, 107, 245, 180);
$randcolor[6] = imagecolorallocate($im, 203, 242, 111);
$randcolor[7] = imagecolorallocate($im, 248, 201, 105);
$data[0] = 30;
$data[1] = 20;
$data[2] = 15;
$data[3] = 10;
$data[4] = 8;
$data[5] = 7;
$data[6] = 5;
$data[7] = 5;
$datasum = array_sum($data);
$deg[0] = number_format((30 / $datasum * 360), 2, ".", "");
$deg[1] = number_format((20 / $datasum * 360), 2, ".", "");
$deg[2] = number_format((15 / $datasum * 360), 2, ".", "");
$deg[3] = number_format((10 / $datasum * 360), 2, ".", "");
$deg[4] = number_format((8 / $datasum * 360), 2, ".", "");
$deg[5] = number_format((7 / $datasum * 360), 2, ".", "");
$deg[6] = number_format((5 / $datasum * 360), 2, ".", "");
$deg[7] = number_format((5 / $datasum * 360), 2, ".", "");
echo ('<pre>');
$datadeg = array();
$datapol = array();
$degbetween = array();
$databetweenpol = array();
for ($i=0; $i < count($deg) ; $i++) {
$datadeg[$i] = get_degtotal($i);
$datapol[$i] = get_polar(200, 200, $datadeg[$i], 100);
}
for ($i=0; $i < count($datadeg) ; $i++) {
$degbetween[$i] = ($datadeg[$i]-2);
$databetweenpol[$i] = get_polar(200, 200, $degbetween[$i], 50);
}
print_r($datadeg);
print_r($degbetween);
print_r($databetweenpol);
for ($i=0; $i<count($deg); $i++) {
imageline ($im, 200, 200, $datapol[$i]['x2'], $datapol[$i]['y2'], $black);
}
imagearc($im, 200, 200, 200, 200, 0, 360, $black);
for ($i=0; $i<count($deg); $i++) {
imagefill ($im, $databetweenpol[$i]['x2'], $databetweenpol[$i]['y2'], $randcolor[$i]);
}
imagepng($im, 'piechart.png');
?>
<img src='piechart.png'>
jerryscript at aol dot com
26-Dec-2003 02:05
[note-Apache/1.3.29 (Win32) PHP/4.3.4]
The imagearc (and imageellipse) functions do not accept line thicknesses when drawn from 0 to 360 degrees.
Drawing from 0 to 359 and again from 359 to 360 does create an ellipse with the current line thickness.
Jerry
eamon at hostelworld dot com
17-Dec-2003 07:24
Right...
possibly the easiest way of drawing a filled circle:
Loop through the imagearc function incrementing the diameter by one pixel:
<?
// --- code fragment --- //
for($i=1; $i<$Diameter; $i++){
imagearc($Image, $CenterX, $CenterY, $i, $i, $Start, $End, $Color);
}
// --------------------- //
?>
This works great for circles with diameters up to about 60 or 70 pixels wide. After that, you start to get pixle gaps.
logang at deltatee dot com
04-Aug-2003 08:19
Heres a function to make a curve between two points... This will be a downward curve but it wouldn't be hard to make a similar function to make an upward curve. The first point has to be to the left of the second point ($x1 < $x2), and height is actually backwards. The larger height is the less of a crest the curve has. I imagine with a few modifications this functions could make upward curves as well.
function ImageCurveDown ($image, $x1, $y1, $x2, $y2, $height, $color) {
$presicion = 1;
for ($left = ($x1-$x2); $left < 0; $left++){
if ($y1 < $y2) {
$cy = $y2 + $height;
$cx = $x1 - $left;
} else {
$cy = $y1 + $height;
$cx = $x2 + $left;
}
$nx1 = abs($x1 - $cx);
$ny1 = abs($y1 - $cy);
$nx2 = abs($x2 - $cx);
$ny2 = abs($y2 - $cy);
if ($y1 < $y2) {
if ($nx2 == 0 || $ny1 == 0) continue;
$angle1 = atan($height/$nx2);
$A1 = $nx2/cos ($angle1);
$B1 = $ny2/sin ($angle1);
$angle2 = pi()/2 +atan($left/$ny1);
$A2 = $nx1/cos ($angle2);
$B2 = $ny1/sin ($angle2);
} else {
if ($ny2 == 0 || $nx1 == 0) continue;
$angle1 = atan($ny2/$nx2);
$A1 = abs($nx2/cos ($angle1));
$B1 = abs($ny2/sin ($angle1));
$angle2 = atan($height/$nx1);
$A2 = abs ($nx1/cos ($angle2));
$B2 = abs($ny1/sin ($angle2));
}
if (abs($A1 - $A2) < $presicion && abs ($B1 - $B2) < $presicion) {
ImageArc($image, $cx, $cy, $A1*2, $B1*2, 180+rad2deg($angle2), 360-rad2deg($angle1), $color);
}
}
}
23-Jan-2003 08:55
Please note that in order to draw a complete circle or ellipse (without using the imageellipse) you mustn't use 0
|
|
|