| cosmokramer |
01-17-2008 12:17 AM |
Quote:
Originally Posted by Wildhoney
(Post 8612)
Hum Interesting. Could you perhaps show us your source code so we can take a closer look?
|
ok and keep in mind this is straight from the tutorial, just changed mysql stuff,
PHP Code:
<?php
Header("Content-type: image/png"); // set as png
mysql_connect("myhost", "myusername", "mypassword") or die("There was an error connecting to the mysql server.");
mysql_select_db("");
// Image Size
$height = 247;
$width = 247;
// Image Pointer, turn on antialiasing
$im = ImageCreate($width, $height); // this is the image
ImageAntiAlias($im, true); // turn it on, just for fun
// Colors
$grass = ImageColorAllocate($im, 67,154,67);
$enemy = ImageColorAllocate($im, 255,0,0);
$bgcolor = ImageColorAllocate($im, 39,104,39);
// exmaple color, not relevant to program.
$white = ImageColorAllocate($im, 255, 0, 0);
ImageFill($im, 0, 0, $bgcolor); // Fill the image with the background color
$size = 5; // size of a block, 5 x 5
$size2 = $size + 1; // don't change this, it is for spacing
$query = "SELECT * FROM `mytable`"; // get all user information
$result = mysql_query($query);
$userarray; // initialize variable
while($row = mysql_fetch_array($result))
{
$userarray[$row['x'] . ',' . $row['y']] = true; // load all the user info we need into an array
}
for($b=0; $b<=40; $b++) // the grid is 40 x 40, this will make the Y columns
{
for($i=0; $i<=40; $i++) // the grid is 40 x 40, this will make the X rows
{
if ($userarray[$i . ',' . $b] == true) // If the $userarray says that there is sombody in this location
{
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $enemy);
}
else
{
// Nobody lives there, draw some grass.
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $grass);
}
}
}
|