Page 554 - Beginning PHP 5.3
P. 554

Part III: Using PHP in Practice
                 complete ellipse). The zero - degree position is at the far right - hand side of the ellipse  —  the 3 o ’ clock
                 position on a clock face  —  as shown in Figure 17 - 10. The degrees progress in a clockwise direction:


                                                270 degrees




                                      Arc height  x, y         0 degrees








                                                 Arc width
                                     Figure 17-10

                   Here ’ s an example of using the  imagearc()  function to draw a partial ellipse:

                    imagearc( $myImage, 90, 60, 160, 50, 45, 200, $myBlack );

                   The first argument,  $myImage , identifies the image in which you ’ re drawing. The next two arguments
                   (90  and  60)  specify the center point of the ellipse that the arc should follow. The width and height
                arguments,   160  and  50 , are the same as in the ellipse example earlier. The next two arguments really
                 create the arc:   45  tells the function to start the arc at the 45 - degree position (at 4:30 if it was a clock) and
                  200  is the position in degrees where the arc is to end. Remember,  200  degrees is the end point, not the
                number of degrees to rotate around the ellipse. Figure 17 - 11 shows the arc drawn from 45 to 200 degrees.








                                              Figure 17-11

                   The arc in the figure may look strange, but remember that the arc is drawn along the ellipse described
                 by the width and height you provide. Compare this arc with the ellipse you drew earlier (see Figure 17 - 8)
                 using the same width and height parameters.

                  Drawing Polygons
                   A polygon is a shape that has three or more corners. To draw a polygon, you use the  imagepolygon()
                 function. Besides passing the image resource to the function, you also need to pass an array of points
                 that define the corners of your polygon. You also need to tell the function how many points there are in
                 the polygon. Finally, as with the other drawing functions, you pass in the color you would like to use.

                   Take a look at the following code:

                    $myPoints = array( 20, 20, 185, 55, 70, 80 );

                    imagepolygon( $myImage, $myPoints, 3, $myBlack );
              516





                                                                                                      9/21/09   2:48:39 PM
          c17.indd   516
          c17.indd   516                                                                              9/21/09   2:48:39 PM
   549   550   551   552   553   554   555   556   557   558   559