Permalink
Browse files

Fixed drawPath method, will now output an image.

  • Loading branch information...
1 parent 6e8ae32 commit 162ebf6dea27791fd8cd03ec6aea8a794d699edd @Dygear committed Mar 29, 2012
Showing with 22 additions and 20 deletions.
  1. +22 −20 modules/prism_pth.php
View
@@ -122,41 +122,43 @@ public function isOnLimit($x, $y, $NodeID)
return true;
}
- /* @arg: $fileName - Filename and Location where to save image.
- */
- function drawPath ($fileName) {
- $im = imagecreate(2560, 2560);
- imagealphablending($im, TRUE);
- $bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
+ public function drawPath ($fileName) {
+ $im = imagecreatetruecolor(2560, 2560);
+ $bg = imagecolorallocate($im, 254, 254, 254);
+ imagefill($im, 0, 0, $bg);
+ imagecolortransparent($im, $bg);
$p =& $this;
- $LeftCos = cos (90 * M_PI/180);
- $LeftSin = sin (90 * M_PI/180);
- $RightCos = cos (-90 * M_PI/180);
- $RightSin = sin (-90 * M_PI/180);
+ $LeftCos = cos (90 * M_PI / 180);
+ $LeftSin = sin (90 * M_PI / 180);
+ $RightCos = cos (-90 * M_PI / 180);
+ $RightSin = sin (-90 * M_PI / 180);
$i = $p->NumNodes - 1;
- $dlx2 = ($p->Nodes[$i]->DirX * $LeftCos - $p->Nodes[$i]->DirY * $LeftSin) * $p->Nodes[$i]->DriveLeft + $p->Nodes[$i]->CentreX;
- $dly2 = ($p->Nodes[$i]->DirY * $LeftCos + $p->Nodes[$i]->DirX * $LeftSin) * $p->Nodes[$i]->DriveLeft + $p->Nodes[$i]->CentreY;
- $drx2 = ($p->Nodes[$i]->DirX * $RightCos - $p->Nodes[$i]->DirY * $RightSin) * -$p->Nodes[$i]->DriveRight + $p->Nodes[$i]->CentreX;
- $dry2 = ($p->Nodes[$i]->DirY * $RightCos + $p->Nodes[$i]->DirX * $RightSin) * -$p->Nodes[$i]->DriveRight + $p->Nodes[$i]->CentreY;
+ $dlx2 = ($p->Nodes[$i]->DirX * $LeftCos - (-$p->Nodes[$i]->DirY) * $LeftSin) * $p->Nodes[$i]->DriveLeft + ($p->Nodes[$i]->CenterX + 1024);
+ $dly2 = ((-$p->Nodes[$i]->DirY) * $LeftCos + $p->Nodes[$i]->DirX * $LeftSin) * $p->Nodes[$i]->DriveLeft + ((-$p->Nodes[$i]->CenterY) + 1024);
+ $drx2 = ($p->Nodes[$i]->DirX * $RightCos - (-$p->Nodes[$i]->DirY) * $RightSin) * -$p->Nodes[$i]->DriveRight + ($p->Nodes[$i]->CenterX + 1024);
+ $dry2 = ((-$p->Nodes[$i]->DirY) * $RightCos + $p->Nodes[$i]->DirX * $RightSin) * -$p->Nodes[$i]->DriveRight + ((-$p->Nodes[$i]->CenterY) + 1024);
+
+ $path_col = imagecolorallocatealpha($im, 64, 64, 64, 64);
- $path_col = imagecolorallocatealpha ($im, 30, 40, 30, 63);
for ($i = 0; $i < $p->NumNodes; $i++) {
- $dlx = ($p->Nodes[$i]->DirX * $LeftCos - $p->Nodes[$i]->DirY * $LeftSin) * $p->Nodes[$i]->DriveLeft + $p->Nodes[$i]->CentreX;
- $dly = ($p->Nodes[$i]->DirY * $LeftCos + $p->Nodes[$i]->DirX * $LeftSin) * $p->Nodes[$i]->DriveLeft + $p->Nodes[$i]->CentreY;
- $drx = ($p->Nodes[$i]->DirX * $RightCos - $p->Nodes[$i]->DirY * $RightSin) * -$p->Nodes[$i]->DriveRight + $p->Nodes[$i]->CentreX;
- $dry = ($p->Nodes[$i]->DirY * $RightCos + $p->Nodes[$i]->DirX * $RightSin) * -$p->Nodes[$i]->DriveRight + $p->Nodes[$i]->CentreY;
+ $dlx = ($p->Nodes[$i]->DirX * $LeftCos - (-$p->Nodes[$i]->DirY) * $LeftSin) * $p->Nodes[$i]->DriveLeft + ($p->Nodes[$i]->CenterX + 1024);
+ $dly = ((-$p->Nodes[$i]->DirY) * $LeftCos + $p->Nodes[$i]->DirX * $LeftSin) * $p->Nodes[$i]->DriveLeft + ((-$p->Nodes[$i]->CenterY) + 1024);
+ $drx = ($p->Nodes[$i]->DirX * $RightCos - (-$p->Nodes[$i]->DirY) * $RightSin) * -$p->Nodes[$i]->DriveRight + ($p->Nodes[$i]->CenterX + 1024);
+ $dry = ((-$p->Nodes[$i]->DirY) * $RightCos + $p->Nodes[$i]->DirX * $RightSin) * -$p->Nodes[$i]->DriveRight + ((-$p->Nodes[$i]->CenterY) + 1024);
$p_array = array ($dlx2, $dly2, $dlx, $dly, $drx, $dry, $drx2, $dry2);
- imagefilledpolygon ($im, $p_array, 4, $path_col);
+
+ imagefilledpolygon($im, $p_array, 4, $path_col);
$dlx2 = $dlx;
$dly2 = $dly;
$drx2 = $drx;
$dry2 = $dry;
}
+
imagepng($im, $fileName);
imagedestroy($im);
}

0 comments on commit 162ebf6

Please sign in to comment.