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<=128;$i++) //create a polygon 128 times
{
drawPoly($x,$y,$im);
$x = $x+2;
$y = $y-2;
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
function drawPoly($xCoord,$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 = imagecolorallocate($im, 150, 150, 150);
$blue = imagecolorallocate($im, 0, 0, 255);
imagefilledpolygon($im, $Poly, 4, $blue);
}
?>[/php]
2 1511
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
The issue is solved. It was the problem with the code.
i took this line $bg = imagecolorallocate($im, 150, 150, 150); outside the function drawPoly(), and everything worked as
expected.
the new updated code is - -
<?php
-
$im = imagecreate(600, 400);
-
$bg = imagecolorallocate($im, 150, 150, 150);
-
$x = 20;
-
$y = 350;
-
for($i=1;$i<=150;$i++) //create a polygon 128 times
-
{
-
drawPoly($x,$y,$im);
-
$x = $x+2;
-
$y = $y-2;
-
}
-
header('Content-type: image/png');
-
imagepng($im);
-
imagedestroy($im);
-
function drawPoly($xCoord,$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 = imagecolorallocate($im, 0, 0, 255);
-
imagefilledpolygon($im, $Poly, 4, $blue);
-
}
-
?>
-
But i still want to know why this happened and why it worked when i took that line outside the function?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: paul |
last post by:
library for querying virtual polygon over raster spatial data
in my c++ application, after calculating my polygon
i wish to define it (simple 4 sided polygon with floats or line parameters)
and...
|
by: Jeronimo Bertran |
last post by:
I have an aspx page that shows a complex image with several objects that
are sensitive to mouseover events. The information about the objects in
the image is obtained from a database and complex...
|
by: BSOB |
last post by:
im gone for a long weekend so plenty of time for anyone to answer.
if i have 4 points representing a polygon and each point is represented by an x and a y coordinate, is there an easy (or slightly...
|
by: André |
last post by:
Hi,
I try to create and render a graphic among other objects like e.g. tables,
labels, buttons.
The tables are not a problem, neither the graphic.
My problem is that i can't render both...
|
by: jojo41300000 |
last post by:
Hi,
Is anyone know that how to get the x and y points inside the polygon using C++ program?
I have the given polygon data to draw the polygon, but i don't know how to get all the points...
|
by: Ofir Picazo |
last post by:
Hello everyone,
I'm trying to crop a polygon (defined as an array of coordinates) from
a larger image. I read lots about gd and imagick but couldn't find an
easy way to do it. Please let me know...
|
by: friendkitty |
last post by:
Hi All,
I m a new member here.I am now writing a program that render Vertex Normals.I m now trying to implement a data structure that will best suit computing vertex normals.For that computation ,...
|
by: moondaddy |
last post by:
I need to be able to make polygons with rounded corners. This will be to
draw group outlines around shapes in a diagramming tool in wpf. all angles
in the polygon will be 90 degrees, but somehow...
|
by: jpatchak |
last post by:
Hello,
I am having a problem using intersects method of a class I made that extends Polygon. Basically, I am trying to write code that allows the user to drag these polygons. I create a 1x1...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |