I have always wanted to make something. Recently, I just got PHP_GD.DLL in PHP4, and I can't wait to do the graphic program to play. Seeing an example of having many PHP making pie charts, I saw 2 days, so I wanted to be a 3D. After the effort, PIE3D is completed, good things share with you. But the younger brother is a new hand of PHP, the code may not be refined enough, I hope everyone will advice to improve this procedure. Remember to inform me (ESTORM@yeah.net)
---------------------- | Pie3DFun.php // Common Function | ------------ ----------
Define ("Angle_Step", 5); // Defines the angle step of the elliptical arc Function CHX_GETDARKCOLOR ($ IMG, $ CLR) {// Request $ CLR Corresponde ($ IMG, $ CLR); Return Array ($ RGB ["RED"] / 2, $ RGB ["Green"] / 2, $ RGB ["Blue"] / 2);
Function CHX_GETEXY ($ a, $ b, $ d) {// Ask the point $ D Corresponding to the point coordinate $ d = deg2rad ($ d); Return Array ($ A * COS ($ D)), Round ($ b * sin)));}
Function CHX_ARC ($ IMG, $ OX, $ OY, $ A, $ B, $ SD, $ ED, $ CLR) {// Elliptical Arc Function $ n = CEIL ($ ED- $ SD) / Angle_Step); $ D = $ sd; list ($ x0, $ y0) = 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); ImagelineLine ($ IMG, $ X0 $ OX, $ Y0 $ OY, $ X $ OX, $ Y $ OY, $ CLR); $ x0 = $ x; $ y0 = $ y;}} Function CHX_Sector ($ IMG, $ OX, $ OY, $ A, $ B, $ SD $ ED, $ CLR) {// Film Noodle $ n = CEIL ($ ED- $ SD) / angle_step); $ d = $ sd; list ($ x0, $ y0) = chx_getexy ($ A, $ B) $ d); Imageline ($ IMG, $ X0 $ OX, $ Y0 $ 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, $ X0 $ OX $ Y0 $ OY, $ y $ y0 = $ x; $ y0 = $ y;} imageline ($ IMG, $ X0 $ OX, $ Y0 $ 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, $ CLR) {// 3D fan CHX_sector ($ IMG, $ OX, $ OY, $ A, $ A B, $ SD, $ ED, $ CLR); IF ($ R, $ G, $ B) = CHX_GETDARKCOLOR ($ IMG, $ CLR); $ CLR = ImageColoralLocate ($ IMG, $ IMG, $ 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, $ 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 Rotation Color $ R = ($ CLR >> 16) & 0xFF $ G = ($ CLR >> 8) & 0xff; $ b = ($ CLR) & 0xff; Return ImageColoralLocate ($ IMG, $ R, $ G, $ B);}
?>
-------------------------- | Pie3d.php // Sani cake diagram file | ---------- ----------------
Require ("Pie3DFun.php");
$ a = 150; // Ellipse long half shaft $ b = 50; // Elliptic segment half shaft $ V = 20; // round cake height $ font = 5; // font
$ OX = 5 $ A; $ = 5 $ b; $ fw = imagefontwidth ($ font); $ funt); $ font;
$ datlst = array (30, 10, 20, 20, 10, 20, 20); // Data $ lablst = Array ("A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8"); // Tag $ CLRLST = Array (0x99FF00, 0XFF66666, 0X0099FF, 0xFF99FF, 0xFFFF99, 0X99FFFF, 0xFF3333, 0x00999);
$ w = 10 $ A * 2; $ h = 10 $ b * 2 $ V ($ FH 2) * Count ($ DATLST);
$ IMG = ImageCreate ($ W, $ H);
// RGB is index color for ($ I = 0; $ I $ CLRBK = ImageColoralLocate ($ IMG, 0xFF, 0xFF, 0xFF); $ CLRT = ImageColoralLocate ($ IMG, 0x00, 0x00, 0x00); // Pack Background Imagefill ($ IMG, 0, 0, $ CLRBK); // Qi $ TOT = 0; for ($ I = 0; $ I $ SD = 0; $ ED = 0; $ LY = 10 $ B * 2 $ V; for ($ I = 0; $ 6 SD = $ ED; $ Ed = $ Datlst [$ I] / $ TOT * 360; // Painted Rubbread CHX_sector3D ($ IMG, $ OX, $ OY $ A, $ B, $ V, $ ED, $ CLRLST [$ I]); // $ SD, $ ED, $ CLRLST [$ I]); // Painting Tag 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]. "(". ("(1000 * ($ DATLST [$ I] / $ Tot)) / 100). "%)", $ CLRT); $ LY = $ FH 2;} // Output Graphic Header ("Content-Type: Image / GIF"); ImageGIF ($ IMG);?>