代码之家  ›  专栏  ›  技术社区  ›  Mark Lalor

使用imagefilledpolygon绘制星形(带图表)

  •  1
  • Mark Lalor  · 技术社区  · 14 年前

    PHP GD有没有办法用 imagefilledpolygon

    这些点将标绘在哪里?

    alt text

    我如何将这些点与 居中 sine cosine 在广东?

    3 回复  |  直到 9 年前
        1
  •  3
  •   CrayonViolent    14 年前

        2
  •  2
  •   Licson    12 年前

    很容易计算出您需要的点数:

    <?php
    function drawStar($img,$x,$y,$radius,$sides,$color,$spikness=0.5)
    {
    $point =array();
    $t = 0;
    for($a = 0;$a <= 360;$a += 360/($sides*2))
    {
    $t++;
    if($t % 2 == 0)
    {
    $point[] = $x + ($radius * $spikness) * cos(deg2rad($a));
    $point[] = $y + ($radius * $spikness) * sin(deg2rad($a));
    }else{
    $point[] = $x + $radius * cos(deg2rad($a));
    $point[] = $y + $radius * sin(deg2rad($a));
    }
    }
    return imagefilledpolygon($img,$point,$sides*2,$color);
    }
    ?>
    
        3
  •  0
  •   Birendra Pradhan    6 年前

    代码如下:

    <?php
       // Create a 200 x 200 image
       $canvas = imageCreateTrueColor(800, 800);
    
       // Allocate colors
       $pink = imageColorAllocate($canvas, 255, 105, 180);
       $white = imageColorAllocate($canvas, 255, 255, 255);
       $green = imageColorAllocate($canvas, 132, 135, 28);
    
       imageLine($canvas, 40, 50, 130, 150, $white);        //draw a line
       imagerectangle($canvas, 150, 50, 250, 150, $pink);   //draw a rectange 
       filled with color
       imageFilledRectangle($canvas, 300, 50, 500, 150, $green);//draw a rectangle
       imageellipse($canvas, 600, 100, 100, 100, $green);   //draw a circle
       $points = array (   76,  228,    // Point 1 (x, y)
                    105, 228,   // Point 2 (x, y)
                    117, 197,   // Point 3 (x, y)
                    129, 228,   // Point 4 (x, y)
                    156, 228,   // Point 5 (x, y)
                    135, 246,   // Point 6 (x, y)
                    149, 285,   // Point 7 (x, y)
                    117, 260,   // Point 8 (x, y)
                    82, 288,    // Point 9 (x, y)
                    98, 245     // Point 10 (x, y)
                );
       imagefilledpolygon( $canvas, $points, 10, $white );//draw a star with polygon()
    
    
       // Output and free from memory
       header('Content-Type: image/png');
    
      imagepng($canvas);
      imagedestroy($canvas);
    ?>