473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filled polygon does not render 129th time on same image

2 New Member
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]
Mar 20 '08 #1
2 1530
ronverdonk
4,258 Recognized Expert Specialist
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
Mar 20 '08 #2
Swan666
2 New Member
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 -
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $im = imagecreate(600, 400);
  3. $bg   = imagecolorallocate($im, 150, 150, 150);
  4. $x = 20;
  5. $y = 350;
  6. for($i=1;$i<=150;$i++) //create a polygon 128 times
  7.     {
  8.         drawPoly($x,$y,$im);
  9.         $x = $x+2;
  10.         $y = $y-2;
  11.     }
  12.     header('Content-type: image/png');
  13.     imagepng($im);
  14.     imagedestroy($im);    
  15.     function drawPoly($xCoord,$yCoord,$im)
  16.     {
  17.         $x1 = $x2 = $xCoord;
  18.         $x3 = $x4 = $xCoord + 70;
  19.         $y1 = $y4 = $yCoord;
  20.         $y2 = $y3 = $yCoord + 30;
  21.         $Poly = array(0  => $x1,1  => $y1,2  => $x2,3  => $y2,4  => $x3,5  => $y3,6  => $x4,7  => $y4);
  22.         $blue = imagecolorallocate($im, 0, 0, 255);
  23.         imagefilledpolygon($im, $Poly, 4, $blue);
  24.     }
  25. ?>
  26.  
But i still want to know why this happened and why it worked when i took that line outside the function?
Mar 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1639
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 use this to query a b/w image in memory, i want to get the pixel counts, full, hopefully partial, perhaps specific to a side, data to calculate area ect, can someone help point me to a library paul
2
1442
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 calculations are performed for each object to determine the position within the image. To render the image I created an aspx page that uses the following code to render the image: Response.ContentType = "image/jpeg";...
6
3655
BSOB
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 less painfull) way to decide whether or not a point (a,b) lays within that polygon? please note that this polygon DOES NOT take the shape of a square and has NO right angles and all side lengths are somewhat random. the application: say i...
4
1795
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 together. With the code below, i only see the graphic, nothing else (no table, label, button). How can i see the table and below the table, the graphic?
3
6167
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 inside the polygon. Eg. Let's say we have 5 points to draw a polygon. Polygon ---------------------
1
3478
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 if you have any ideas. Thanks
3
2242
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 , my data structure should have accessed to the faces adjacent to each vertices. first i read all vertices ,and faces from .m file into a structure.And stored in vectors. vector<Vertex> vertices; vector<Face> faces; Then i render that model.No...
6
10840
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 I wanted to make the corners a bit rounded (otherwise it will look like an old legacy app). Is this possible in wpf? The reason I wanted to use a polygon was because I will bind an adorner to each point so the user can drag the corners around to...
8
2989
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 rectangle on a mouse press and look through an array to see if the rectangle intersects the polygon. If it does, then I call the polygon's move class, passing the x and y coordinates while the user is dragging. Problem is that it works the first time,...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10384
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10395
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6887
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.