Recipe 17.3. Drawing with Patterned Lines17.3.2. ProblemYou 17.3.3. SolutionTo draw shapes with a patterned line, use $black = ImageColorAllocate($image, 0, 0, 0); 17.3.4. DiscussionThe line pattern is defined by an array of colors. Each element in the array is another pixel in the brush. It's often useful to repeat the same color in successive elements, as this increases the size of the stripes in the pattern. For instance, here is code for a square drawn with alternating white and black pixels, as shown in the left side of Figure 17-4: $style = array($white, $black); This is the same square, but drawn with a style of five white pixels followed by five black ones, as shown in the middle of Figure 17-4: $style = array($white, $white, $white, $white, $white, Three squares with alternating white and black pixelsThe patterns look completely different, even though both styles are just white and black pixels. If the brush doesn't fit an integer number of times in the shape, it wraps around. In the previous examples, the square is 50 pixels wide. Since the first brush is 2 pixels long, it fits exactly 25 times; the second brush is 10 pixels, so it fits 5 times. But if you make the square 45 by 45 and use the second brush, you don't get straight lines as you did previously, as shown in the right side of Figure 17-4: ImageFilledRectangle($image, 0, 0, 44, 44, IMG_COLOR_STYLED); 17.3.5. See AlsoRecipes Recipe 17.1 and Recipe 17.2 for more on drawing shapes; documentation on ImageSetStyle( ) at http://www.php.net/imagesetstyle. |
Friday, January 8, 2010
Recipe 17.3. Drawing with Patterned Lines
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment