All pastes #794163 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-22 23:04 UTC
rendered paste body
<?
//version: 1195772503

$db['hostname'] = 'localhost';
$db['username'] = 'root';
$db['password'] = '';
$db['database'] = 'opensim';

mysql_connect($db['hostname'],$db['username'],$db['password']);
@mysql_select_db($db['database']) or die( "Unable to select database");
$query = "SELECT regionName, locX, locY FROM regions ORDER BY locX ASC, locY ASC, regionName DESC;";
$result = mysql_query($query);


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
	$regions[$row['regionName']] = array('locX' => $row['locX'], 'locY' => $row['locY']);
}

mysql_free_result($result);

mysql_close();

print_r($regions);

foreach($regions as $regionName => $coords)
{
	print_r($regionName);
	print_r($coords);
}

//Width and height of each region
$regionSize = 50;

//Center on a coordinate
$centerX = 1000;
$centerY = 1000;

//set X, Y upper bounds
$maxX = 1005;
$maxY = 1005;

//set X, Y lower bounds
$minX = 995;
$minY = 995;

//Create an image, properly sized
$imageWidth = (($maxX-$minX)*$regionSize);
$imageHeight = (($maxY-$minY)*$regionSize);

echo $imageWidth;
echo $imageHeight;

$heading = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" width="'.$imageWidth.'" height="'.$imageHeight.'" id="svg2">';

//foreach region, plot square at position in image multiplied by region width
foreach($regions as $regionName => $coords)
{
	if($coords['locX'] > $minX AND $coords['locX'] < $maxX)
	{
		if($coords['locY'] > $minY AND $coords['locY'] < $maxY)
		{
			$rectangles .= '<rect width="'.$regionSize.'" height="'.$regionSize.'" x="'.($coords['locX']-$centerX)*$regionSize.'" y="'.($coords['locY']-$centerY)*$regionSize.'" style="opacity:1;fill:#00ff00;fill-opacity:1;stroke:#000000;stroke-width:1.00430417;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" id="'.$regionName.'_rectangle" />';

			$text .= '<text id="'.mt_rand().'"><tspan x="'.((($coords['locX']-$centerX)*$regionSize)).'" y="'.((($coords['locY']-$centerY)*$regionSize)+($regionSize/2)).'" style="font-size:10px;font-family:Serif" id="'.$regionName.'_text">'.$regionName.'</tspan></text>';
		}
	}
}

$ending = '</svg>';

$stringData = $heading.$rectangles.$text.$ending;
$fh = fopen('map.svg', 'w');
fwrite($fh, $stringData);
fclose($fh);

echo '<EMBED SRC="map.svg" WIDTH="1000" HEIGHT="1000">'

?>