filled polygon does not render 129th time on same image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Swan666
    New Member
    • Mar 2008
    • 2

    #1

    filled polygon does not render 129th time on same image

    I have a function which creates a polygon of blue color. I call this function inside a loop of 128 iterations. For every iteration, i change the value of x and y so that my polygon is rendered on new location. This goes fine and i get 128 new polygons on my image after running the script. But if change the number to 129, the 129th polygon is transparent or what i cannot guess.It just does not display or render at all. Is this a bug or some mistake with my code?

    I am using php version 5.1.4 that came with WAMP5 Version 1.6.3

    my code is -
    [php]<?php
    $im = imagecreate(600 , 400);
    $x = 20;
    $y = 350;
    for($i=1;$i<=12 8;$i++) //create a polygon 128 times
    {
    drawPoly($x,$y, $im);
    $x = $x+2;
    $y = $y-2;
    }
    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($i m);
    function drawPoly($xCoor d,$yCoord,$im)
    {
    $x1 = $x2 = $xCoord;
    $x3 = $x4 = $xCoord + 70;
    $y1 = $y4 = $yCoord;
    $y2 = $y3 = $yCoord + 30;
    $Poly = array(0 => $x1,1 => $y1,2 => $x2,3 => $y2,4 => $x3,5 => $y3,6

    => $x4,7 => $y4);
    $bg = imagecoloralloc ate($im, 150, 150, 150);
    $blue = imagecoloralloc ate($im, 0, 0, 255);
    imagefilledpoly gon($im, $Poly, 4, $blue);
    }
    ?>[/php]
    Last edited by ronverdonk; Mar 20 '08, 07:19 PM. Reason: code within code tags!!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • Swan666
      New Member
      • Mar 2008
      • 2

      #3
      The issue is solved. It was the problem with the code.

      i took this line $bg = imagecoloralloc ate($im, 150, 150, 150); outside the function drawPoly(), and everything worked as

      expected.

      the new updated code is -
      [code=php]
      <?php
      $im = imagecreate(600 , 400);
      $bg = imagecoloralloc ate($im, 150, 150, 150);
      $x = 20;
      $y = 350;
      for($i=1;$i<=15 0;$i++) //create a polygon 128 times
      {
      drawPoly($x,$y, $im);
      $x = $x+2;
      $y = $y-2;
      }
      header('Content-type: image/png');
      imagepng($im);
      imagedestroy($i m);
      function drawPoly($xCoor d,$yCoord,$im)
      {
      $x1 = $x2 = $xCoord;
      $x3 = $x4 = $xCoord + 70;
      $y1 = $y4 = $yCoord;
      $y2 = $y3 = $yCoord + 30;
      $Poly = array(0 => $x1,1 => $y1,2 => $x2,3 => $y2,4 => $x3,5 => $y3,6 => $x4,7 => $y4);
      $blue = imagecoloralloc ate($im, 0, 0, 255);
      imagefilledpoly gon($im, $Poly, 4, $blue);
      }
      ?>
      [/code]

      But i still want to know why this happened and why it worked when i took that line outside the function?

      Comment

      Working...