Jump to content

draw dynamic polygons


AviNahum

Recommended Posts

hey...

im making a simple game, and im trying to draw a dynamic polygon around each star in the game to show the stars area.

for example, lets say "STAR A" positioned on X=50,Y=100 on the map, in the database i have a colum that determine the star's surended area for example, area=100; is that posible to darw a polygon around each star depending on the star area on the DB? another think is that each polygon shuold be in diffrent color. im not asking for the full soultion, but if someone can please give me some directions how to do it... im not good at math :|

i made an image to demostarate what im trying to reach...

 

Thanks in advance...


post-71948-0-69375800-1363704545_thumb.png

Edited by aviavi
Link to comment
Share on other sites

found the 'drawStar' function below from stack overflow user licson, made this script draw random stars... is this more of what you need?

Edit: sorry, misread what you said.... this draws stars. still a good function though, lol. How do you plan to determine the boundaries, or the dynamics of each polygon?

 

// function grabbed from user "licson" on stackoverflow.com
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);
}
 
$im = imagecreate(500, 500);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
 
for($i=0; $i<10; $i++)
{
    drawStar($im, rand(0,500), rand(0,500), rand(20,50), rand(5, , $white);
}
 
// output image to browser
header('Content-Type: image/jpeg');
imagejpeg($im,"",100);
 
// destroy the image
imagedestroy($source);
imagedestroy($im);
Edited by fooDigi
Link to comment
Share on other sites

i'll explain better...

i have a div with a background, i call it the galaxy...

inside the galaxy div there a few div's with absalute position, i call each div like this a star...

i need that each star will be surounded with a polygon as i demostrated in the picture...

Link to comment
Share on other sites

Your example showed neighbouring areas having common boundaries and you also state the area of the polygon must be as specified in the table. I'm not sure these two can both be achieved.

 

If stars are placed randomly, what prevents a star being placed within the area of another star?

 

Are all stars in place before drawing the boundaries?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.