Drawing a PolygonIf you want to draw your own figures, you can trace them together using multiple lines, but there's an easier wayyou can use the imagepolygon function to draw a polygon simply by passing it an array of points. Here's how you use this function in general:
This function creates a polygon in image. The points array is a PHP array containing the polygon's vertices (points[0] = x0, points[1] = y0, points[2] = x1, points[3] = y1, and so on). The num_points value holds the total number of points in the polygon, and color is the drawing color you want to use. For example, here's an array of points, $points, in which every pair of values (array[0] and array[1], array[2] and array[3], and so on) specifies a point on the screen:
Now we can draw the resulting polygon with imagepolygon:
The whole example appears in phppolygon.php, Example 6. Example 6. Drawing polygons, phppolygon.php
We'll use an HTML document, phppolygon.html, to host the new image:
The new polygon appears in Figure 7. Very nice. Figure 7. Drawing a polygon.[View full size image] |
Wednesday, October 28, 2009
Drawing a Polygon
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment