Pokemon Dark Phantom Gold Finger Code php three-dimensional pie chart implementation code

Source: Internet
Author: User
After the efforts Pie3d finished, good things to share with you. But the younger brother is a novice PHP, the code may not be refined, I hope that everyone to improve the program together. Remember to call me (estorm@yeah.net)
+------------------------+
| pie3dfun.php//Common Functions |
+------------------------+
Define ("Angle_step", 5);//defines the angle step for drawing an elliptical arc
function Chx_getdarkcolor ($img, $CLR) {//$clr the corresponding dark color
$rgb =imagecolorsforindex ($img, $CLR);
return Array ($rgb ["Red"]/2, $rgb ["Green"]/2, $rgb ["Blue"]/2);
}
function chx_getexy ($a, $b, $d) {//$d point coordinates on the ellipse corresponding to the angle
$d =deg2rad ($d);
Return Array (round ($a *cos ($d)), round ($b *sin ($d)));
}
function Chx_arc ($img, $ox, $oy, $a, $b, $SD, $ed, $CLR) {//elliptic arc function
$n =ceil (($ed-$SD)/angle_step);
$d = $SD;
List ($x 0, $y 0) =chx_getexy ($a, $b, $d);
for ($i =0; $i < $n; $i + +) {
$d = ($d +angle_step) > $ed $ed:($d +angle_step);
List ($x, $y) =chx_getexy ($a, $b, $d);
Imageline ($img, $x 0+ $ox, $y 0+ $oy, $x + $ox, $y + $oy, $CLR);
$x 0= $x;
$y 0= $y;
}
}
function Chx_sector ($img, $ox, $oy, $a, $b, $SD, $ed, $CLR) {//Draw slices
$n =ceil (($ed-$SD)/angle_step);
$d = $SD;
List ($x 0, $y 0) =chx_getexy ($a, $b, $d);
Imageline ($img, $x 0+ $ox, $y 0+ $oy, $ox, $oy, $CLR);
for ($i =0; $i < $n; $i + +) {
$d = ($d +angle_step) > $ed $ed:($d +angle_step);
List ($x, $y) =chx_getexy ($a, $b, $d);
Imageline ($img, $x 0+ $ox, $y 0+ $oy, $x + $ox, $y + $oy, $CLR);
$x 0= $x;
$y 0= $y;
}
Imageline ($img, $x 0+ $ox, $y 0+ $oy, $ox, $oy, $CLR);
List ($x, $y) =chx_getexy ($a/2, $b/2, ($d + $sd)/2);
Imagefill ($img, $x + $ox, $y + $oy, $CLR);
}
function Chx_sector3d ($img, $ox, $oy, $a, $b, $v, $SD, $ed, $clr) {//3d fan
Chx_sector ($img, $ox, $oy, $a, $b, $SD, $ed, $CLR);
if ($sd <180) {
List ($R, $G, $B) =chx_getdarkcolor ($img, $CLR);
$CLR =imagecolorallocate ($img, $R, $G, $B);
if ($ed >180) $ed = 180;
List ($SX, $sy) =chx_getexy ($a, $b, $SD);
$SX + = $ox;
$sy + = $oy;
List ($ex, $ey) =chx_getexy ($a, $b, $ed);
$ex + = $ox;
$ey + = $oy;
Imageline ($img, $SX, $sy, $SX, $sy + $v, $CLR);
Imageline ($img, $ex, $ey, $ex, $ey + $v, $CLR);
Chx_arc ($img, $ox, $oy + $v, $a, $b, $SD, $ed, $CLR);
List ($SX, $sy) =chx_getexy ($a, $b, ($SD + $ed)/2);
$sy + = $oy + $v/2;
$SX + = $ox;
Imagefill ($img, $SX, $sy, $CLR);
}
}
function Chx_getindexcolor ($img, $clr) {//RBG goto index color
$R = ($clr >>16) & 0xFF;
$G = ($clr >>8) & 0xFF;
$B = ($CLR) & 0xFF;
Return Imagecolorallocate ($img, $R, $G, $B);
}
?>
+--------------------------+
| pie3d.php//three-dimensional pie chart File |
+--------------------------+
Require ("pie3dfun.php");
$a =150;//oval long half shaft
$b =50;//ellipse Segment Half axis
$v =20;//Cake Height
$f//font
$ox =5+ $a;
$oy =5+ $b;
$FW =imagefontwidth ($font);
$FH =imagefontheight ($font);
$datLst =array (30,10,20,20,10,20,10,20);//Data
$labLst =array ("A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8");//Label
$clrLst =array (0x99ff00,0xff6666,0x0099ff,0xff99ff,0xffff99,0x99ffff,0xff3333,0x009999);
$w =10+ $a.
$h =10+ $b *2+ $v + ($fh +2) *count ($datLst);
$img =imagecreate ($w, $h);
Turn RGB to indexed color
for ($i =0; $i
$CLRBK =imagecolorallocate ($img, 0xff,0xff,0xff);
$CLRT =imagecolorallocate ($img, 0x00,0x00,0x00);
Fill background color
Imagefill ($img, 0,0, $CLRBK);
Sum
$tot = 0;
for ($i =0; $i
$SD = 0;
$ed = 0;
$ly =10+ $b *2+ $v;
for ($i =0; $i $sd = $ed;
$ed + = $datLst [$i]/$tot *360;
Draw a round cake
Chx_sector3d ($img, $ox, $oy, $a, $b, $v, $SD, $ed, $clrLst [$i]);//$SD, $ed, $clrLst [$i]);
Draw Labels
Imagefilledrectangle ($img, 5, $ly, 5+ $fw, $ly + $fh, $clrLst [$i]);
Imagerectangle ($img, 5, $ly, 5+ $fw, $ly + $fh, $CLRT);
Imagestring ($img, $font, 5+2* $FW, $ly,
$labLst [$i]. ":" $datLst [$i]. " (". (Round (10000* ($datLst [$i]/$tot)/100). "%)",
$CLRT);
$ly + = $fh +2;
}
Output graphics
Header ("Content-type:image/gif");
Imagegif ($IMG);
?>

The above describes the Pokemon dark Phantom Gold Finger Code php three-dimensional pie chart implementation code, including the Pokemon Dark Phantom Gold finger Code content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.