/**
  * Displays the finally calculated string of next life cycle.
  *
  */
 public function displayResult()
 {
     $arrayToString = "";
     for ($i = 0; $i < $this->height; $i++) {
         for ($j = 0; $j < $this->width; $j++) {
             if ($this->gameField->isAlive($i, $j)) {
                 $arrayToString .= "x";
             } else {
                 $arrayToString .= "-";
             }
         }
     }
     echo $arrayToString;
 }
Example #2
0
 /**
  * Displays the finally calculated gif with all life cycles.
  *
  * @param int $_numGifFrames Amount of life cycles the gif returned should consists (standard=100).
  */
 public function displayResult($_numGifFrames = 100)
 {
     $frames = [];
     $delayTime = [];
     for ($x = 0; $x < $_numGifFrames; $x++) {
         $im = @ImageCreateTrueColor($this->width * 10, $this->height * 10) or die("Kann keinen neuen GD-Bild-Stream erzeugen");
         $delayTime[$x] = 5;
         $background_color = ImageColorAllocate($im, 255, 255, 255);
         imagefill($im, 0, 0, $background_color);
         $black = ImageColorAllocate($im, 0, 0, 0);
         for ($i = 0; $i < $this->height; $i++) {
             for ($j = 0; $j < $this->width; $j++) {
                 if ($this->gameField->isAlive($i, $j)) {
                     imagefilledrectangle($im, $j * 10, $i * 10, $j * 10 + 10, $i * 10 + 10, $black);
                 }
             }
         }
         ob_start();
         imagegif($im);
         $frames[$x] = ob_get_contents();
         ob_end_clean();
         imagedestroy($im);
         $this->calculateNextLifeCycle();
     }
     /*  usage external GIF-Encoder:
         image_stream = new GIFEncoder	(
                                 URL or Binary data	'Sources'
                                 int					'Delay times'
                                 int					'Animation loops'
                                 int					'Disposal'
                                 int					'Transparent red, green, blue colors'
                                 int					'Source type');*/
     $gif = new GIFEncoder($frames, $delayTime, 0, 2, 0, 0, 0, "bin");
     /*  Possibles outputs:
         ==================
         Output as GIF for browsers :                   -> Header ( 'Content-type:image/gif' );
         Output as GIF for browsers with filename:      -> Header ( 'Content-disposition:Attachment;filename=myanimation.gif');
         Output as file to store into a specified file: -> FWrite ( FOpen ( "myanimation.gif", "wb" ), $gif->GetAnimation ( ) );*/
     Header('Content-type:image/gif');
     echo $gif->GetAnimation();
 }