Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Atelier] Fond animé Space Invaders

Venez vous entraîner avec le langage de votre choix :)

Anonyme
    26 avril 2013 à 14:30:58

    Voici également ma version, en javascript avec canvas.

    469 caractères avec html, 419 sans:

    <canvas width="1600"height="900"><script>m=Math;c=document.body.querySelector("canvas").getContext("2d");r=function(e){return(f=m.floor)(m.random()*e)};p="001010001111100101010010101011111111010101";d=function(e,t){c.fillRect((a+e)*55,(b+t)*55,50,50)};setInterval(function(){c.clearRect(0,0,1e4,1e4);c.fillStyle="rgb("+r(256)+","+r(256)+","+r(256)+")";a=r(32);b=r(18);for(i=0;i<42;i++)if(p[i]>"0")d(i%7,f(i/7));c.fillStyle="black";d(2,2+r(2));d(4,2+r(2))},1e3)</script>
    



    • Partager sur Facebook
    • Partager sur Twitter
      26 avril 2013 à 14:32:12

      Moi je dis, pourquoi faire simple quand on peut faire compliqué ?

      PHP & JS (ajax)

      <?php
      define('BASE', __DIR__.DIRECTORY_SEPARATOR);
      define('X', 40);
      define('Y', 30);
      
      /**
       * @property-read Input $input
       * @property-read Loader $loader
       * @property-read Router $router
       */
      class Core implements ArrayAccess{
          /**
           * @var Core
           */
          private static $_instance = null;
          private $vars=array();
      
          private function __construct() {
              self::$_instance = $this;
      
              $autoload = array('Input', 'Router');
              $this->loader = new Loader($autoload);
          }
      
          public function __get($name){
              return isset($this[$name]) ? $this[$name] : null;
          }
      
          public function __isset($name) {
              return isset($this[$name]);
          }
      
          public function __set($name, $value){
              $this[$name] = $value;
          }
      
          public function offsetSet($offset, $value) {
              $this->vars[$offset] = $value;
          }
      
          public function offsetGet($offset) {
              return isset($this->vars[$offset]) ? $this->vars[$offset] : null;
          }
      
          public function offsetExists($offset) {
              return isset($this->vars[$offset]);
          }
      
          public function offsetUnset($offset) {
              unset($this->vars[$offset]);
          }
      
          public function execute(){
              $function = $this->router->selectRoute();
              $exec_param = array();
              $reflec = new ReflectionFunction($function);
      
              foreach($reflec->getParameters() as $param){
                  $value = $this->input->{$param->getName()};
                  if($value===false){
                      if($param->isDefaultValueAvailable())
                          $value = $param->getDefaultValue();
                      else
                          $value = null;
                  }
                  $exec_param[] = $value;
              }
      
              $reflec->invokeArgs($exec_param);
          }
      
          /**
           * @return Core
           */
          public static function instance(){
              if(self::$_instance===null)
                  new self;
              return self::$_instance;
          }
      }
      abstract class Component{
          /**
           * @var Core
           */
          private $_instance;
      
          public function __construct() {
              $this->_instance = Core::instance();
          }
      
          public function __get($name) {
              return $this->_instance->$name;
          }
      
          public function __set($name, $value) {
              $this->_instance->$name = $value;
          }
      }
      class Loader extends Component{
          public function __construct(array $autoload) {
              parent::__construct();
      
              foreach($autoload as $class)
                  $this->load($class);
          }
          public function get($class_name){
              if($this->{strtolower($class_name)}===null)
                  $this->load($class_name);
              return $this->{strtolower($class_name)};
          }
      
          public function load($name){
              if(!class_exists($name)){
                  throw new Exception(<<<MSG
                                  La classe "$name" n'existe pas, ou n'est pas encore incluse !
      MSG
      );
              }
              if($this->{strtolower($name)}!==null){
                  throw new Exception(<<<MSG
                                  La class "$name" est déjà chargée !
      MSG
      );
              }
              $this->{strtolower($name)} = new $name;
          }
      }
      class Router{
          private $action = '';
          private $_routes = array();
      
          public function __construct() {
              if(!($this->action=Core::instance()->input->action))
                  $this->action = 'layout';
          }
      
          public function register($name, callable $function){
              $this->_routes[$name] = $function;
          }
      
          public function selectRoute(){
              foreach($this->_routes as $name=>$function){
                  if((~$name & $this->action)===str_repeat(chr(0), strlen($this->action))){
                      return $function;
                  }
              }
              throw new Exception('Erreur 404');
          }
      }
      class Cache{
          const EXT = '.cache';
          
          public function get($name){
              $file = self::processName($name);
              if(!file_exists($file))
                  return false;
      
              $data = unserialize(file_get_contents($file));
      
              if($data['destruct_time'] < time()){
                  unlink($file);
                  return false;
              }
      
              return $data['content'];
          }
      
          public function set($name, $value, $time = 60){
              $file = self::processName($name);
      
              if(!is_dir(dirname($file)))
                  mkdir(dirname ($file), 0777, true);
      
              $data = array(
                  'content' => $value,
                  'destruct_time' => time() + $time
              );
      
              return file_put_contents($file, serialize($data));
          }
      
          private static function processName($name){
              return BASE.'cache'.DIRECTORY_SEPARATOR.str_replace('.', DIRECTORY_SEPARATOR, $name).self::EXT;
          }
      }
      class Input{
          public function __get($name){
              foreach($_GET + $_POST as $k => $v){
                  if(($k & $name)==$name)
                      return urldecode(trim($v));
              }
              return false;
          }
      }
      class HtmlPage{
          private $code = '';
      
          public function addContent($content){
              $this->code.=$content;
              return $this;
          }
      
          public function __toString() {
              return $this->code;
          }
      }
      class HtmlTag{
          private $content = '';
          private $name = '';
          private $attributes = array();
      
          public function __construct($name, array $attributes = array()){
              $this->name = $name;
              $this->attributes = $attributes;
          }
      
          public function addContent($content){
              $this->content.=$content;
              return $this;
          }
          
          public function __toString() {
              $open = '<'.$this->name.' ';
              foreach($this->attributes as $name=>$value){
                  if(is_numeric($name))
                      $open.=$value.' ';
                  else
                      $open.=$name.'="'.addslashes($value).'" ';
              }
              $open.='>';
              $close = '</'.$this->name.'>';
      
              return $open.$this->content.$close;
          }
      }
      class Invader{
          private static $pattern = [
              [0, 0, 1, 0, 1, 0, 0],
              [0, 1, 1, 1, 1, 1, 0],
              [0, 1, 0, 1, 0, 1, 0],
              [0, 1, 0, 1, 0, 1, 0],
              [1, 1, 1, 1, 1, 1, 1],
              [1, 0, 1, 0, 1, 0, 1]
          ];
          private $color;
          private $eyes = array();
      
          public function __construct() {
              $this->color = rand(0, 0xFFFFFF);
              $this->eyes = array_fill(0, 6, array_fill(0, 7, 0));
              $this->eyes[rand(2, 3)][2] = 1;
              $this->eyes[rand(2, 3)][4] = 1;
          }
      
          /**
           * @return Mapper
           */
          public function getMap($size_x, $size_y){
              $map = new Mapper($size_x, $size_y);
              $pos_x = rand(0, $size_x - count(self::$pattern[0]));
              $pos_y = rand(0, $size_y - count(self::$pattern));
      
              $map->fill(self::$pattern, $this->color, $pos_x, $pos_y);
              $map->fill($this->eyes, 0, $pos_x, $pos_y);
      
              return $map;
          }
      }
      class Mapper{
          private $map;
          private $X;
          private $Y;
      
          public function __construct($x, $y){
              $this->map = array_fill(0, $y, array_fill(0, $x, null));
              $this->X = $x;
              $this->Y = $y;
          }
      
          public function fill(array $pattern, $color, $x_pos, $y_pos){
              foreach($pattern as $y => $row){
                  foreach($row as $x => $fill){
                      if($fill)
                          $this->map[($y_pos + $y) % $this->Y][($x_pos + $x) % $this->X] = $this->intToHexColor($color);
                  }
              }
          }
      
          private function intToHexColor($i){
              $hex = dechex($i);
              while(strlen($hex) < 6){
                  $hex = '0'.$hex;
              }
      
              return '#'.$hex;
          }
      
          public function toJSON(){
              return json_encode($this->map);
          }
      }
      
      $core = Core::instance();
      
      set_exception_handler(function(Exception $e){
          echo '<pre>', $e, '</pre>';
          exit;
      });
      
      $core->router->register(
              'layout',
              function($size_x = 40, $size_y = 30, $speed = 1500) use($core){
          $size_x = abs((int)$size_x);
          $size_y = abs((int)$size_y);
          $speed = abs((int)$speed);
                  if(!($data=$core->loader->get('Cache')->get('layout'))){
                      $data = new HtmlPage();
                      $head = new HtmlTag('head');
                      $x = (100 / $size_x) - 1;
                      $y = (100 / $size_y) - 1;
                      $head->addContent((new HtmlTag('style'))->addContent(<<<TXT
         div{
             margin: 1px;
             width: $x%;
             height: $y%;
             padding: 3px;
             display: inline-block;
         }
      TXT
      ));
                      $head->addContent((new HtmlTag('script', array('type'=>'text/javascript')))->addContent(<<<SCRIPT
      
         var X = $size_x;
         var Y = $size_y;
          window.setTimeout(loadInvader, 1000);
      
          function loadInvader(){
              xhr = new XMLHttpRequest();
              xhr.open("GET", "index.php?action=invader&size_x=" + X + "&size_y=" + Y, false);
              xhr.send(null);
              fillPage(JSON.parse(xhr.responseText));
              window.setTimeout(loadInvader, $speed);
          }
      
          function fillPage(map){
              for(var y in map){
                  for(var x in map[y]){
                      var id = "block_" + x + "_" + y;
                      document.getElementById(id).style.background = map[y][x];
                  }
              }
          }
      SCRIPT
      ));
                      $data->addContent($head);
                      $body = new HtmlTag('body');
                      for($y = 0; $y < $size_y; $y++){
                          for($x = 0; $x < $size_x; $x++){
                              $id = 'block_'.$x.'_'.$y;
                              $body->addContent((new HtmlTag('div', array('id'=>$id)))->addContent(' '));
                          }
                          $body->addContent('<br/>');
                      }
                      $data = (string)$data->addContent($body);
                      $core->cache->set('layout.'.$size_x.'x'.$size_y.'@'.$speed, $data, 3600);
                  }
                  echo $data;
              }
      );
      
      $core->router->register('invader', function($size_x = 40, $size_y = 30){
          $invader = new Invader;
          echo $invader->getMap(abs((int)$size_x), abs((int)$size_y))->toJSON();
      });
      
      $core->execute();
      Je compte bien gagner le prix du code le plus inutilement compliqué x)

       test : http://www.ynova.fr/invaders.php

      -
      Edité par v4vx 26 avril 2013 à 16:47:25

      • Partager sur Facebook
      • Partager sur Twitter
        26 avril 2013 à 14:43:24

        v4vx a écrit:

        Je compte bien gagner le prix du code le plus inutilement compliqué x)

        Ah non, ca va être moi! Je posterais quand j'aurais terminé, language Java.



        • Partager sur Facebook
        • Partager sur Twitter
        Dans le Mouton, tout est bon!
          26 avril 2013 à 14:50:11

          Gnarkinou a écrit:

          v4vx a écrit:

          Je compte bien gagner le prix du code le plus inutilement compliqué x)

          Ah non, ca va être moi! Je posterais quand j'aurais terminé, language Java.

          Ho non :'(

          • Partager sur Facebook
          • Partager sur Twitter
            26 avril 2013 à 15:02:58

            Un petit deuxième pour moi :D

            Inspiré par le code en C de lucas-84 je l'ai écrit en Bash pour une console de 80x24

            #!/bin/bash
            while [ 1 ];do	
            	a=$(($RANDOM%17));
            	b=$(($RANDOM%65));
            	s="";
            	u=( 0 _ );
            	v=( _ 0 );
            	w=$(($RANDOM%2));
            	x=$(($RANDOM%2));
            	c=$((($RANDOM%8)+30));
            	clear;
            	for e in `seq 0 $b`;do
            		s="$s ";
            	done
            	for e in `seq 0 $a`;do
            		echo -ne '\n';
            	done
            	printf "\e[1;%dm%s      _   _\n%s    _|_|_|_|_\n%s   |_|_|_|_|_|\n%s   |_|%c|_|%c|_|\n%s  _|_|%c|_|%c|_|_\n%s |_|_|_|_|_|_|_|\n%s |_| |_| |_| |_|\n" "$c" "$s" "$s" "$s" "$s" "${u[w]}" "${u[x]}" "$s" "${v[w]}" "${v[x]}" "$s" "$s";
            	sleep 1;
            done



            -
            Edité par sylv1pdt 26 avril 2013 à 15:13:05

            • Partager sur Facebook
            • Partager sur Twitter
              26 avril 2013 à 16:02:30

              Salut tout le monde, pour ma part, c'est PHP, HTML et AJAX :)

              Et je n'ai pas fait dans le plus simple, loin de là ! Il y a de l'inutile. Beaucoup même :p
              Au départ je souhaitais lefaire carrément avec Symfony (je vous ai dit que je faisait dans l'inutile !) mais finalement ça m'aurait gonflé :p

              http://si.teamsolex.eu/

              voici le code: 

              index.php

              <?php
              
              function autoload($class)
              {
                require 'class/'.$class.'.class.php';
              } 
              spl_autoload_register('autoload');
              srand();
              
              $scale = 0.6;
              $delay = 3;
              
              if(isset($_GET['h']) && isset($_GET['w'])){ 
              	$h = $_GET['h'];
              	$w = $_GET['w'];
              	
              	$s1 = new Seed(0);
              	$top = floor(($h-6*100*$scale-100)*$s1->getSeed());
              	$s2 = new Seed(0);
              	$left = floor(($w-7*100*$scale-100)*$s2->getSeed());
              	
              	echo json_encode(array(	"top"	=>	$top,
              								"left"	=>	$left));
              	exit;	
              }	
              
              $invader = new Invader(new Seed(), $scale, $delay);
              echo $invader->getHTML();
              
              ?>

              Invader.class.php

              <?php
              
              class Invader{
              
              	private $cells;
              	
              	private $color;
              	
              	private $template;
              	private $title;
              	private $css;
              	private $content;
              	private $refresh;
              	
              	private $x;
              	private $y;
              	private $scale;
              	
              	
              	public function __construct($seed, $scale, $refresh){
              		$this->scale = $scale;
              		$this->refresh = $refresh;
              		$this->color = new Color($seed);
              		$this->color = $this->color->generate();
              		$this->cells = array(array());
              		for($i=0;$i<7;$i++){
              			for($j=0;$j<6;$j++){
              				$this->cells[$i][$j] = new Cell($this->color, $this->scale);
              				$this->cells[$i][$j]->setPosition($i,$j);
              			}
              		}
              		$this->addFirstEye(new Eye($this->scale));
              		$this->addSecndEye(new Eye($this->scale));		
              		
              		$this->template = new Template("index");
              	}
              	
              	public function addFirstEye($e){
              		$fe = $this->getFirstEye();
              		$fe[0]->setColor($e->getTopCell()->getColor());
              		$fe[1]->setColor($e->getBottomCell()->getColor());
              		//$fe[1] = $e->getBottomCell();
              	}	
              	public function addSecndEye($e){
              		$fe = $this->getSecndEye();
              		$fe[0]->setColor($e->getTopCell()->getColor());
              		$fe[1]->setColor($e->getBottomCell()->getColor());
              	}	
              	public function getFirstEye(){
              		return array($this->cells[2][2],$this->cells[2][3]);
              	}
              	public function getSecndEye(){
              		return array($this->cells[4][2],$this->cells[4][3]);
              	}
              	public function colorCells($c){
              		foreach($cells as $cell){
              			$cell->color($c);
              		}
              	}
              	private function setTemplate($t){
              		$this->template = $t;
              	}
              	private function setTitle($t){
              		$this->title = $t;
              	}
              	public function getCss(){
              		$css = "";
              		$css .= $this->getBaseCss();
              		foreach($this->cells as $cell){
              			foreach($cell as $cel){
              				$css .= $cel->getCss()."
              			";
              			}
              		}
              		return $css;
              	}
              	public function getContent(){
              		$content = "";
              		foreach($this->cells as $cell){
              			foreach($cell as $cel){
              				$content .= $cel->getHTML();
              			}
              		}
              		return $content;
              	}
              	private function setRefresh($r){
              		$this->refresh = $r;
              	}
              	
              	public function getHTML(){
              		return $this->template->render(array(	"css"		=>	$this->getCss(),
              							"title"		=>	"Space Invader",
              							"content"	=>	$this->getContent(),
              							"invader.pos.top"		=> $this->x,
              							"invader.pos.bottom"	=> $this->y,
              							"scale"	=>	$this->scale,
              							"invader.pos.left"	=>	$this->x,
              							"invader.pos.top"	=>	$this->y));
              	}
              
              }
              
              ?>
              


              Cell.class.php

              <?php
              
              class Cell{
              	
              	private $x;
              	private $y;
              	private $scale;
              	private $color;
              	
              	public function __construct($color, $scale){
              		$this->color = $color;
              		$this->scale = $scale;
              	}
              	public function setPosition($x, $y){
              		$this->x = $x;
              		$this->y = $y;
              		$this->checkColorByZone();
              	}
              	
              	public function checkColorByZone(){
              		$whiteSpots = array(	"00",	"01",	"03",	"05",	"06",
              								"10",	"16",
              								"20",	"22",	"24",	"26",
              								"30",	"32",	"34",	"36",
              								"51",	"53",	"55");
              		$loc = $this->y.$this->x;
              		if(in_array($loc, $whiteSpots)){
              			$this->color = new Color(0);
              			$this->color->setRGB(255, 255, 255);
              		}
              	}
              	
              	public function getHtml(){
              		return '<div id="block'.$this->x.$this->y.'" class="pixel"></div>
              			';
              	}
              	public function getCss(){
              	return 
              	'#block'.$this->x.$this->y.'{
              			width: '.$this->getW().'px;
              			height: '.$this->getH().'px;
              			background-color: '.$this->color->getRGB().';
              			color: '.$this->color->getRGB().';
              			position: absolute; 
              			top:'.$this->getTop().'px; 
              			left:'.$this->getLeft().'px; 
              			border-color: white;
              			border-size: 2px;
              			display: none;
              		}';
              	}
              	public function getH(){
              		return 100*$this->scale;
              	}
              	public function getW(){
              		return 100*$this->scale;
              	}
              	public function getLeft(){
              		return $this->x*100*$this->scale;
              	}
              	public function getTop(){ // left et top du positionnement absolute côté CSS
              		return $this->y*100*$this->scale;
              	}
              	public function getColor(){
              		return $this->color;
              	}
              	public function setColor($c){
              		$this->color = $c;
              		return $this;
              	}
              	
              }
              
              ?>
              


              Color.Class.php

              <?php
              
              class Color{
              
              	private $r;
              	private $g;
              	private $b;
              	private $seed;
              	
              	public function __construct($seed){
              		$this->seed = $seed;
              	}
              	
              	public function generate(){
              	
              		$seed = $this->seed->getSeed();
              		$this->r = floor(255*$seed);		
              		$s2 = new Seed();
              		$this->g = floor(255*$s2->getSeed());		
              		$s3 = new Seed();
              		$this->b = floor(255*$s3->getSeed());
              		
              		return $this;
              	}
              	
              	public function getRGB(){
              		return "rgb(".$this->r.", ".$this->g.", ".$this->b.")";
              	}
              	
              	public function getR(){
              		return $this->r;
              	}
              	public function getG(){
              		return $this->g;
              	}
              	public function getB(){
              		return $this->b;
              	}
              	
              	public function setR($r){
              		$this->r = $r;
              		return $this;
              	}
              	public function setG($r){
              		$this->g = $g;
              		return $this;
              	}
              	public function setB($r){
              		$this->b = $b;
              		return $this;
              	}
              	public function setRGB($r, $g, $b){
              		$this->r = $r;
              		$this->g = $g;
              		$this->b = $b;
              		return $this;
              	}
              
              }
              
              ?>

              Eye.class.php

              <?php
              
              class Eye{
              	
              	private $cellTop;
              	private $cellBottom;
              	
              	public function __construct($scale){
              	$seed = new Seed();
              		$black = new Color($seed);
              		$black->setRGB(0, 0, 0);
              		$white = new Color($seed);
              		$white->setRGB(255, 255, 255);
              		if(floor(100*$seed->getSeed())%2 == 0){
              			$this->cellTop = new Cell($black, $scale);
              			$this->cellBottom = new Cell($white, $scale);
              		}else{
              			$this->cellTop = new Cell($white, $scale);
              			$this->cellBottom = new Cell($black, $scale);
              		}
              	}
              	
              	public function getTopCell(){
              		return $this->cellTop;
              	}
              	public function getBottomCell(){
              		return $this->cellBottom;
              	}
              }
              
              ?>

              Seed.class.php (le comble de l'inutile !)

              <?php
              
              class Seed{
              	
              	public function __construct(){
              	}
              	
              	public function getMe(){
              		return $this;
              	}
              	public function getSeed(){
              		return mt_rand()/mt_getrandmax();
              	}
              }
              
              ?>

              Template.class.php

              <?php
              
              class Template{
              
              	private $tpl;
              	
              	public function __construct($name){
              		$this->tpl = file_get_contents("tpl/".$name.".tpl");
              	}
              	
              	public function render($tplVars){
              		foreach($tplVars as $varName => $value){
              			$this->tpl = preg_replace("$\{\{".$varName."\}\}$", $value, $this->tpl);
              		}
              		return $this->tpl;
              	}
              
              }
              
              ?>
              

              Et pour finir le HTML + JS dans index.tpl

              <html>
              	<head>
              		<title>{{title}}</title>
              		<script type="text/javascript">
              			function createXHR(){
              				var xhr; 
              					try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
              					catch (e){
              						try {   xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
              						catch (e2){
              						   try {  xhr = new XMLHttpRequest();  }
              						   catch (e3) {  xhr = false;   }
              						 }
              					}
              				return xhr;
              			}
              			function update(){
              				var xhr = createXHR();
              				
              				xhr.onreadystatechange = function (){
              					if(xhr.readyState == 4){
              						if(xhr.status == 200){
              							//alert(xhr.responseText);
              							var response = JSON.parse(xhr.responseText);
              							var container = document.getElementById("container");
              							container.style.top = response.top;
              							container.style.left = response.left;
              							container.style.position = "absolute";
              							
              							var blocks = document.getElementsByClassName("pixel");	
              							for(var i = 0; i < blocks.length; i++) {
              								blocks[i].style.display = 'block';
              							}
              						}else{
              							alert("Code d'erreur "+xhr.responseText);
              						}
              					}
              				}
              				xhr.open('GET', "/index.php?w="+screen.availWidth+"&h="+screen.availHeight, true);
              				xhr.send(null);
              			}
              		</script>
              		<meta http-equiv="refresh" content="{{refresh}}" >
              		<style type="text/css">
              		body{
              			background: #ffffff;
              		}
              		.container{
              			position: absolute;
              			top: {{invader.pos.top }}px;
              			left: {{invader.pos.left }}px;
              			background: #ffffff;
              			width: ({{scale}}*100+5)*7;
              			height: ({{scale}}*100+5)*6;
              		}
              		.pixel{
              			border-width: 5px;
              			border-color: #ffffff;
              			border-style: solid;
              		}
              		{{css}}</style>
              	</head>
              	<body onload="update()" >
              		<div id="container">
              			{{content}}
              		</div>
              	</body>
              </html>
              


              Voilà je crois pouvoir dire sans trop me tromper que je suis parmi ceux qui ont fait le plus compliqué/inutilé ! :lol:

              -
              Edité par Varamox 26 avril 2013 à 16:04:45

              • Partager sur Facebook
              • Partager sur Twitter
                26 avril 2013 à 16:03:43

                Idem, un deuxième pour moi... en BrainFuck :D

                +++++[>+++++++>++++++>+++<<<-]>>++>--<..<.>.....<.>..>.<...<.>...<.>...>.<..<.......>..>.<.<..>.<...>.<..>.>.<<...........>>.<<.>.<.......>.<.>>.<<.>.<.>.....<.>.<.>>.<...<..>.<..>...

                Et avec un peu d'indentation :

                +++++
                [
                >+++++++>++++++>+++<<<-
                ]
                >>++
                >--
                <..<.>.....<.>..
                >.
                <...<.>...<.>...
                >.
                <..<.......>..
                >.
                <.<..>.<...>.<..>.
                >.
                <<...........
                >>.
                <<.>.<.......>.<.
                >>.
                <<.>.<.>.....<.>.<.
                >>.
                <...<..>.<..>...

                Pour ceux qui veulent tester, copier-coller le code dans cette page :magicien:

                Bon je reconnais, c'est pas vraiment une animation (je crée juste un invader) mais il y a pas moyen de faire un sleep en BF...

                Par contre au niveau taille du code, je m'en sors honorablement avec 183 octets :)

                Invader en ASCII BrainFuck

                -
                Edité par Eskimon 26 avril 2013 à 16:08:51

                • Partager sur Facebook
                • Partager sur Twitter

                Retrouvez moi sur mon blog et ma chaine Youtube !

                Anonyme
                  26 avril 2013 à 16:15:49

                  Bon pour moi c'est en C (C99 pour les déclarations de variables dans les for) avec la SDL.:)

                  Je vais essayer de l'améliorer un peu,voici ce qui j'ai pour l'instant:

                  #include <SDL/SDL.h>
                  #include <stdio.h>
                  #include <stdlib.h>
                  #include <time.h>
                  
                  int main(void)
                  {
                  	if(!SDL_Init(SDL_INIT_VIDEO))
                  	{
                  		SDL_Surface* video=SDL_SetVideoMode(800,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
                  		if(video!=NULL)
                  		{
                  			char skin[6]={20,62,42,42,127,85},quit=0;
                  			Uint32 last=0;
                  			srand(time(NULL));
                  			while(!quit)
                  			{
                  				SDL_Event event;
                  				while(SDL_PollEvent(&event))
                  				{
                  					if(event.type==SDL_QUIT)
                  					{
                  						quit=1;
                  					}
                  				}
                  				if(SDL_GetTicks()-last>1024)
                  				{
                  					SDL_Rect rect={rand()%688,rand()%504,15,15};
                  					const Uint32 color=SDL_MapRGB(video->format,rand()%256,rand()%256,rand()%256);
                  					skin[3]=(skin[2]^=(rand()&20))^20;
                  					SDL_FillRect(video,NULL,SDL_MapRGB(video->format,255,255,255));
                  					for(size_t i=0;i<6;++i)
                  					{
                  						for(char j=0;j<7;++j)
                  						{
                  							const char actual=skin[i]&1<<j;
                  							if(actual)
                  							{
                  								SDL_FillRect(video,&rect,color*(!(i&2)||actual&42));
                  							}
                  							rect.x+=16;
                  						}
                  						rect.x-=112;
                  						rect.y+=16;
                  					}
                  					SDL_Flip(video);
                  					last=SDL_GetTicks();
                  				}
                  			}
                  		}
                          SDL_Quit();
                      }
                  	return EXIT_SUCCESS;
                  }
                  

                  Version ultra-réduite (!!!pas de gestion des events ni des erreurs!!!):

                  #include <SDL/SDL.h>
                  #include <stdio.h>
                  #include <stdlib.h>
                  #include <time.h>
                  #define N rand()
                  #define Z SDL_MapRGB
                  int main(void){SDL_Surface*v=SDL_SetVideoMode(800,600,32,0);char s[6]={20,62,42,42,127,85};while(1){SDL_Rect r={N%688,N%504,15,15};int c=Z(v->format,N%256,N%256,N%256);s[3]=(s[2]^=(N&20))^20;SDL_FillRect(v,NULL,Z(v->format,255,255,255));for(size_t i=0;i<6;++i){for(char j=0;j<7;++j){char a=s[i]&1<<j;if(a)SDL_FillRect(v,&r,c*(!(i&2)||a&42));r.x+=16;}r.x-=112;r.y+=16;}SDL_Flip(v);SDL_Delay(1024);}return 0;}
                  
                  
                  :p


                  EDIT: Optimisations^^

                  EDIT2: Réduction du nombre de caractères.

                  -
                  Edité par Anonyme 17 mai 2013 à 19:07:47

                  • Partager sur Facebook
                  • Partager sur Twitter
                    26 avril 2013 à 16:41:19

                    Ma version en AWK qui génère du code html. :) 

                    BEGIN{}
                    {
                       le=int(rand()*2);
                       re=int(rand()*2);
                       hexa=int(rand()*16777215);
                       printf("<table style=\"margin-left:%dpx; margin-top:%dpx;\">",int(rand()*512),int(rand()*512));
                       for(i=0;i<6;i++){
                       print "<tr>"
                          for(j=0;j<7;j++){
                             if(((i==0)&&((j==2)||(j==4)))||((i==1)&&((j!=0)&&(j!=6)))||(((i>1)&&(i<4))&&((j%2)==1))||(i==4)||((i==5)&&((j%2)==0)))
                                color = hexa;
                             else if(((i==2)&&(j==2)&&(le))||((i==3)&&(j==2)&&(!le))||((i==2)&&(j==4)&&(re))||((i==3)&&(j==4)&&(!re)))
                    	    color = 0;
                    	 else 
                    	    color = 16777215;
                    	 printf("<td style=\"background:#%06X\" width=\"10\" height=\"10\">", color);
                          }
                       print "</tr>"}
                       print "</table>"
                    }END{}

                    664 octects, on peut faire mieux ^^.

                    Petit aperçu...



                    • Partager sur Facebook
                    • Partager sur Twitter
                    Anonyme
                      26 avril 2013 à 16:58:23

                      Une petite version entièrement en HTML/CSS, avec la particulatiré de créer l'invader autrement qu'en générant les "blocs" de couleurs.

                      Ce coups ci, je créer le carré en couleur, et j'y ajoute les blanc :rire:

                      Version 1: http://www.ptitworldwarien.fr/invader/noJs1.html

                      Version 2: http://www.ptitworldwarien.fr/invader/noJs2.html

                      -
                      Edité par Anonyme 26 avril 2013 à 16:59:49

                      • Partager sur Facebook
                      • Partager sur Twitter
                        26 avril 2013 à 17:06:34

                        Le but est de faire un animé "aléatoire" hein ? ;)
                        • Partager sur Facebook
                        • Partager sur Twitter
                          26 avril 2013 à 18:03:04

                          allez moi je me lance dans une version en TI-basic ! ( version TI-82stat.fr ^^)

                          pas tout finis encore , mais c’est déjà très inutile , et pas du tout concis :p

                          • Partager sur Facebook
                          • Partager sur Twitter
                          l´experience est une longue suite de connerie
                          Anonyme
                            26 avril 2013 à 18:12:17

                            v4vx a écrit:

                            Le but est de faire un animé "aléatoire" hein ? ;)


                            L'aléatoire de position, de couleur, de quoi que ce soit est impossible en CSS. (en html aussi d'ailleurs)

                            D'ailleurs, si on va par là, l'aléatoire est impossible à obtenir avec une machine.

                            Quoi qu'il en soit, si tu veux du pseudo aléatoire, ma première version ira très bien. Je suis aller sur cette version ci dans le sens de mathéo21 : tableless et plus court. La rotation servant à rien, mais m'a fais travailler les keyframes en css.

                            • Partager sur Facebook
                            • Partager sur Twitter
                              26 avril 2013 à 19:33:55

                              Alexis's a écrit:

                              v4vx a écrit:

                              Le but est de faire un animé "aléatoire" hein ? ;)


                              L'aléatoire de position, de couleur, de quoi que ce soit est impossible en CSS. (en html aussi d'ailleurs)

                              D'ailleurs, si on va par là, l'aléatoire est impossible à obtenir avec une machine.

                              Quoi qu'il en soit, si tu veux du pseudo aléatoire, ma première version ira très bien. Je suis aller sur cette version ci dans le sens de mathéo21 : tableless et plus court. La rotation servant à rien, mais m'a fais travailler les keyframes en css.


                              mais animé est possible en css, ainsi que donne une impression d'aléatoire (d'où le fait que j'ai mis entre guillemets).

                              Pour corser le tout, sans même utiliser rand() de php :p

                              Lien : https://gist.github.com/vincent4vx/5462513(sa prend trop de place directement sur le forum :x )

                              -
                              Edité par v4vx 26 avril 2013 à 19:35:34

                              • Partager sur Facebook
                              • Partager sur Twitter
                                26 avril 2013 à 20:07:21

                                Ma version : http://duge.noue.chez.com/SpaceInvaders/

                                index.html : 

                                <html>
                                <head>
                                <link rel = "stylesheet" src = style.css" />
                                <title>Space Invaders</title>
                                </head>
                                <body>
                                <div id = "div">
                                	<span></span><span></span><span></span><span></span><span></span><span></span><span></span><br />
                                	<span></span><span></span><span></span><span></span><span></span><span></span><span></span><br />
                                	<span></span><span></span><span id = "b"></span><span></span><span id = "c"></span><span></span><span></span><br />
                                	<span></span><span></span><span id = "a"></span><span></span><span id = "d"></span><span></span><span></span><br />
                                	<span></span><span></span><span></span><span></span><span></span><span></span><span></span><br />
                                	<span></span><span></span><span></span><span></span><span></span><span></span><span></span><br />
                                </div>
                                <script src = "script.js">
                                </script>
                                </body>
                                </html>

                                script.js : 

                                var ida = Math.floor ( Math.random() * 200 );
                                var idb = Math.floor ( Math.random() * 200 );
                                if( ida	< 100 )
                                {
                                	ida = "a";
                                }
                                else
                                {
                                	ida = "b";
                                }
                                if( idb	< 100 )
                                {
                                	idb = "c";
                                }
                                else
                                {
                                	idb = "d";
                                }
                                var couleur = Math.floor ( Math.random() * 300 );
                                if(couleur < 100){document.getElementById( "div" ).style.backgroundColor = "green";}
                                else if(couleur < 200 && couleur > 100){document.getElementById( "div" ).style.backgroundColor = "red";}
                                else{document.getElementById( "div" ).style.backgroundColor = "yellow";}
                                document.getElementById( ida ).style.backgroundColor = "black";
                                document.getElementById( idb ).style.backgroundColor = "black";
                                document.getElementById( "div" ).style.top = String(Math.round(0 + Math.random() * (452 - 0))) + "px";
                                document.getElementById( "div" ).style.left = String(Math.round(0 + Math.random() * (956- 0))) + "px";
                                window.setTimeout('history.go()', 2000);

                                style.css : 

                                span:nth-of-type(1), span:nth-of-type(2), span:nth-of-type(4), span:nth-of-type(6), span:nth-of-type(7), span:nth-of-type(8), span:nth-of-type(14), span:nth-of-type(15), span:nth-of-type(17), span:nth-of-type(19), span:nth-of-type(21), span:nth-of-type(22), span:nth-of-type(28), span:nth-of-type(24), span:nth-of-type(26), span:nth-of-type(37), span:nth-of-type(39), span:nth-of-type(41)
                                {
                                	background-color: white;
                                	opacity: 1;
                                }
                                @-webkit-keyframes grossir
                                { 
                                	from
                                	{
                                		height: 32px;
                                		width: 32px;
                                	}
                                	50%
                                	{
                                		height: 48px;
                                		width: 48px;
                                	}
                                	to
                                	{
                                		height:32px;
                                		width: 32px;
                                	} 
                                }
                                @-moz-keyframes grossir
                                { 
                                	from
                                	{
                                		height: 32px;
                                		width: 32px;
                                	}
                                	50%
                                	{
                                		height: 48px;
                                		width: 48px;
                                	}
                                	to
                                	{
                                		height:32px;
                                		width: 32px;
                                	} 
                                }
                                @-ms-keyframes grossir
                                { 
                                	from
                                	{
                                		height: 32px;
                                		width: 32px;
                                	}
                                	50%
                                	{
                                		height: 48px;
                                		width: 48px;
                                	}
                                	to
                                	{
                                		height:32px;
                                		width: 32px;
                                	} 
                                }
                                @-o-keyframes grossir
                                { 
                                	from
                                	{
                                		height: 32px;
                                		width: 32px;
                                	}
                                	50%
                                	{
                                		height: 48px;
                                		width: 48px;
                                	}
                                	to
                                	{
                                		height:32px;
                                		width: 32px;
                                	} 
                                }
                                span
                                {
                                	-webkit-animation: grossir 2s linear 0s;
                                        -moz-animation: grossir 2s linear 0s;
                                         -ms-animation: grossir 2s linear 0s;
                                          -o-animation: grossir 2s linear 0s;
                                             animation: grossir 2s linear 0s;
                                	opacity: 0;
                                	width: 32px;
                                	height: 32px;
                                	display: inline-block;
                                }
                                div
                                {
                                	position: absolute;
                                	background-color: black;
                                }

                                désolé pour l'indentation, j'utilise le bloc-notes et j'ai eu la flemme de la faire...

                                -
                                Edité par _mrtn 27 avril 2013 à 14:10:30

                                • Partager sur Facebook
                                • Partager sur Twitter

                                Je ne visite plus ce site, si ça vous intéresse (ce qui serait très curieux), lisez ma bio.

                                  26 avril 2013 à 21:17:25

                                  Voilà mon code, VB.NET, code assez propre, rendu assez dégueulasse quand le nouveau space invader arrive, mais sur les pc rapides ça ne se voit pas.

                                  (ET FAIT AVEC LES WINDOWS FORMS, S'IL VOUS PLAIT :D)

                                  Imports System.Windows.Forms
                                  
                                  Public Class Main
                                      Inherits Form
                                  
                                      WithEvents MainForm As New Form
                                      WithEvents Timer As New Timer
                                      Dim Positions As New List(Of List(Of Drawing.Point))
                                      Dim Generator As New Random
                                      Dim SI As Drawing.Bitmap
                                  
                                      Sub New()
                                  
                                          Form.CheckForIllegalCrossThreadCalls = False
                                  
                                          MainForm.Size = My.Computer.Screen.Bounds.Size
                                          MainForm.Opacity = 0
                                          MainForm.ShowInTaskbar = False
                                          MainForm.ShowIcon = False
                                          MainForm.FormBorderStyle = FormBorderStyle.None
                                          MainForm.Location = New Drawing.Point(0, 0)
                                          MainForm.BackColor = Drawing.Color.White
                                  
                                          For y = 0 To 5
                                              Positions.Add(New List(Of Drawing.Point))
                                              For x = 0 To 6
                                                  Positions(y).Add(New Drawing.Point((x * 54), (y * 54)))
                                              Next
                                          Next
                                  
                                          SI = RefreshSpaceInvader(Drawing.Color.Black)
                                  
                                          MainForm.Show()
                                          ShowInTaskbar = False
                                          ShowIcon = 0
                                          Me.Hide()
                                  
                                          For i = 0 To 1.01 Step 0.01
                                              MainForm.Opacity = i
                                              Threading.Thread.Sleep(15)
                                          Next
                                  
                                          Timer.Interval = Generator.Next(2000, 5000)
                                          Timer.Start()
                                  
                                      End Sub
                                  
                                      Function RefreshSpaceInvader(ByVal EyesColor As Drawing.Color) As Drawing.Bitmap
                                  
                                          Dim SpaceInvader As New Drawing.Bitmap(428, 374)
                                  
                                          Dim EyesPositions() As Drawing.Point = {If(Generator.Next(0, 10000) < 5000, Positions(2)(2), Positions(3)(2)), If(Generator.Next(0, 10000) < 5000, Positions(2)(4), Positions(3)(4))}
                                          Dim BodyColor As Drawing.Color = Drawing.Color.FromArgb(Generator.Next(0, 256), Generator.Next(0, 256), Generator.Next(0, 256))
                                          Dim BodyPositions() As Drawing.Point = {Positions(0)(2), Positions(0)(4), _
                                                                                  Positions(1)(1), Positions(1)(2), Positions(1)(3), Positions(1)(4), Positions(1)(5), _
                                                                                  Positions(2)(1), Positions(2)(3), Positions(2)(5), _
                                                                                  Positions(3)(1), Positions(3)(3), Positions(3)(5), _
                                                                                  Positions(4)(0), Positions(4)(1), Positions(4)(2), Positions(4)(3), Positions(4)(4), Positions(4)(5), Positions(4)(6), _
                                                                                  Positions(5)(0), Positions(5)(2), Positions(5)(4), Positions(5)(6)}
                                  
                                          For Each Position As Drawing.Point In BodyPositions
                                              For x = 0 To 50 - 1
                                                  For y = 0 To 50 - 1
                                                      SpaceInvader.SetPixel(Position.X + x, Position.Y + y, BodyColor)
                                                  Next
                                              Next
                                          Next
                                  
                                          For Each EyePosition As Drawing.Point In EyesPositions
                                              For x = 0 To 50 - 1
                                                  For y = 0 To 50 - 1
                                                      SpaceInvader.SetPixel(EyePosition.X + x, EyePosition.Y + y, Drawing.Color.Black)
                                                  Next
                                              Next
                                          Next
                                  
                                          SpaceInvader.MakeTransparent(Drawing.Color.White)
                                  
                                          Return SpaceInvader
                                  
                                      End Function
                                  
                                      Private Sub MainForm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MainForm.KeyPress
                                          If Asc(e.KeyChar) = Keys.Escape Then
                                              Application.Exit()
                                          End If
                                      End Sub
                                  
                                      Private Sub MainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MainForm.Paint
                                          Me.Hide()
                                          e.Graphics.DrawImage(SI, New Drawing.Point(Generator.Next(0, My.Computer.Screen.Bounds.Size.Width - 428), Generator.Next(0, My.Computer.Screen.Bounds.Size.Height - 324)))
                                      End Sub
                                  
                                      Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick
                                          Timer.Interval = Generator.Next(2000, 5000)
                                          SI = RefreshSpaceInvader(Drawing.Color.Black)
                                          MainForm.Hide()
                                          MainForm.Show()
                                      End Sub
                                  
                                  End Class
                                  Si vous voulez l'utiliser, mettez vous en Windows Forms, supprimer la votre et ajoutez une classe, vous copiez le code, et voilà :p
                                  • Partager sur Facebook
                                  • Partager sur Twitter
                                  MysteryDash / 100 MPM / Développeur Freelance C#.NET / osu! / PS4 Offline Remote Play
                                    26 avril 2013 à 21:38:33

                                    Salut,

                                    je ne sais pas si j'ai le droit mais voilà ma version en scratch (http://scratch.mit.edu/ ) :

                                    http://space-invaders-sdz.voila.net/

                                    et voilà mon code: 

                                    C'est sur c'est plus facile comme mais je n'ai que 13 ans et je n'avait pas le niveau pour le faire dans un autre langage (Même si j'y travaille).

                                    (PS : cliquez sur "en savoir plus sur ce projet" car étrangement cela marche mieux)

                                    -
                                    Edité par roro28mi 26 avril 2013 à 21:42:34

                                    • Partager sur Facebook
                                    • Partager sur Twitter
                                      27 avril 2013 à 2:38:21

                                      Bonjour, voici ma version de la chose en camllight  en essayant au mieux de faire le plus court possible. Par contre l'actualisation du graph necessite la fonction "unix__spleep" disponible comme son nom l'indique uniquement sur linux.

                                      Voilà les environs 490 caractères sans les commentaires évidemment:

                                      #open "graphics";;
                                      open_graph "";;  (*on affiche un graphique de taille standard*)
                                      
                                      while 0=0 do      (*boucle infinie et true comporte une lettre de plus que 0=0*)
                                        let f a = a mod 256 and g a = random__int a       (*définition de fonctions pour gagner des caractères*)
                                        
                                        and t=[|0;0;1;0;1;0;0;
                                      	   0;1;1;1;1;1;0;
                                      	   0;1;0;1;0;1;0;
                                      	   0;1;0;1;0;1;0;
                                      	   1;1;1;1;1;1;1;
                                      	   1;0;1;0;1;0;1|] in     (*le tableau comportant l'invader*)
                                      
                                        let  x,y,z = (g 480),(g 310),g 256 in  (*3 entiers aléatoires pour la couleur et les coordonéées*)
                                      	
                                        t.(16+(x mod 2)*7)<-1;t.(18+(z mod 2)*7)<-1;  (*on place les yeux aléatoirement suivant la parité de x et z*)
                                      		
                                        for k=0 to 41 do
                                          if k=16 or k=18 or k=23 or k=25 then set_color black               (*la couleur noire pour les yeux*)
                                            else set_color(rgb (f z) (f x) (f y));                           (*pour le reste la couleur aléatoire*)
                                          if t.(k)=1 then  fill_rect (x+20*(k mod 7)) (y+120-20*(k/7)) 18 18 (*on place un carré là où j'ai dit grâce à t*)
                                        done;
                                      
                                        unix__sleep 2;clear_graph();    (*puis on admire 2 sec et on efface pour recommencer*)
                                      done;;

                                      -
                                      Edité par la Bécasse 27 avril 2013 à 10:21:34

                                      • Partager sur Facebook
                                      • Partager sur Twitter
                                        27 avril 2013 à 11:34:10

                                        Salut,

                                        J'apporte ma modeste contribution avec un fond d'écran Space Invader pour Android. :)

                                        Code source sur GitHub.

                                        • Partager sur Facebook
                                        • Partager sur Twitter
                                        Si vous voulez me retrouver, rendez-vous sur ZesteDeSavoir.
                                          27 avril 2013 à 11:37:18

                                          Aller, jamais  sans trois :)

                                          Version Ti-BASIC (version TI-82) cette fois (donc pas de couleur :x), avec des mini-invaders :)

                                          :[[0,0,1,0,1,0,0][0,1,1,1,1,1,0][0,1,0,1,0,1,0][0,1,0,1,0,1,0][1,1,1,1,1,1,1][1,0,1,0,1,0,1]]->[A]
                                          :While 1
                                          :ent(NbrAléat*90)->X
                                          :ent(NbrAléat*60)->Y
                                          :For(A,1,6
                                          :For(B,1,7
                                          :If [A](A,B)=1:Pxl-On(Y+A,X+B
                                          :End:End
                                          :Pxl-On(Y+3+ent(NbrAléat*2),X+3
                                          :Pxl-On(Y+3+ent(NbrAléat*2),X+5
                                          :For(K,0,120):End
                                          :EffDessin
                                          :End
                                          Totalisant en tout 214 octets ! (Hé oui, les fonction en Ti-BASIC sont du Byte-Code :D )
                                          (Si quelqu'un arrive à faire moins lourd, je dis chapeau :o )
                                          • Partager sur Facebook
                                          • Partager sur Twitter
                                            27 avril 2013 à 12:15:52

                                            Eskimon a écrit:

                                            Bon je reconnais, c'est pas vraiment une animation (je crée juste un invader) mais il y a pas moyen de faire un sleep en BF...

                                            Par contre au niveau taille du code, je m'en sors honorablement avec 183 octets :)

                                            v4vx a écrit:

                                            Totalisant en tout 214 octets ! (Hé oui, les fonction en Ti-BASIC sont du Byte-Code:D )
                                            (Si quelqu'un arrive à faire moins lourd, je dis chapeau :o )



                                            Tu pourras dire chapeau à Eskimon :D.


                                            • Partager sur Facebook
                                            • Partager sur Twitter
                                            Développeur de GroovySearch (site down pour l'instant)
                                              27 avril 2013 à 12:18:42

                                              Kokopak a écrit:

                                              Eskimon a écrit:

                                              Bon je reconnais, c'est pas vraiment une animation (je crée juste un invader) mais il y a pas moyen de faire un sleep en BF...

                                              Par contre au niveau taille du code, je m'en sors honorablement avec 183 octets :)

                                              v4vx a écrit:

                                              Totalisant en tout 214 octets ! (Hé oui, les fonction en Ti-BASIC sont du Byte-Code:D )
                                              (Si quelqu'un arrive à faire moins lourd, je dis chapeau :o )



                                              Tu pourras dire chapeau à Eskimon :D.


                                              Lui je lui tire mon chapeau plus pour le BF, mais malheureusement (limite du BF), par de random :x

                                              • Partager sur Facebook
                                              • Partager sur Twitter
                                                27 avril 2013 à 12:46:12

                                                Bon ...

                                                J'ai fais ce code vite fait

                                                #include <unistd.h>
                                                #define l(_,k)'!'-!(_&k)
                                                #define H(x)printf("%*s\n",a,(char[]){l(x,64),l(x,32),l(x,16),l(x,8),l(x,4),l(x,2),l(x,1),0});
                                                main(){int a=rand()%100,t=a*3%20;system("clear");while(t--)puts("");H(20)H(62)H(42)H(42)H(255)H(85)sleep(1),main();}


                                                Exactement 256 octets ... Dont 116 qui ne sont pas du code préprocesseur et 236o sans l’include ... J'ai pas réussit à faire un code entier de moins de 214, à 42octets près j'étais trop loin pour chercher encore à faire plus court ... Je peux encore gagné 1 ou 2 octets mais pas plus ...


                                                PS: Un code de 256 octets, qui contient 2 fois 42, et qui est à 42octets de la limite que je cherche à atteindre ... :soleil:
                                                C'est du C hein ;) Pas du tout portable (Linux et peut-être mac). Aucune norme n'est respecté  ...
                                                Il y a peut-être moyen de faire plus court au niveau de la fonction d'affichage ...

                                                -
                                                Edité par @che 27 avril 2013 à 12:51:39

                                                • Partager sur Facebook
                                                • Partager sur Twitter

                                                🍊 - Étudiant - Codeur en C | Zeste de Savoir apprenez avec une communauté | Articles  - ♡ Copying is an act of love.

                                                  27 avril 2013 à 13:19:26

                                                  @che a écrit:

                                                  Bon ...

                                                  J'ai fais ce code vite fait

                                                  #include <unistd.h>
                                                  #define l(_,k)'!'-!(_&k)
                                                  #define H(x)printf("%*s\n",a,(char[]){l(x,64),l(x,32),l(x,16),l(x,8),l(x,4),l(x,2),l(x,1),0});
                                                  main(){int a=rand()%100,t=a*3%20;system("clear");while(t--)puts("");H(20)H(62)H(42)H(42)H(255)H(85)sleep(1),main();}


                                                  Exactement 256 octets ... Dont 116 qui ne sont pas du code préprocesseur et 236o sans l’include ... J'ai pas réussit à faire un code entier de moins de 214, à 42octets près j'étais trop loin pour chercher encore à faire plus court ... Je peux encore gagné 1 ou 2 octets mais pas plus ...


                                                  PS: Un code de 256 octets, qui contient 2 fois 42, et qui est à 42octets de la limite que je cherche à atteindre ... :soleil:
                                                  C'est du C hein ;) Pas du tout portable (Linux et peut-être mac). Aucune norme n'est respecté  ...
                                                  Il y a peut-être moyen de faire plus court au niveau de la fonction d'affichage ...

                                                  -
                                                  Edité par @che il y a 22 minutes


                                                  Il marche ce code ? :o

                                                  Si c'est le cas, GG :)

                                                  • Partager sur Facebook
                                                  • Partager sur Twitter
                                                    27 avril 2013 à 13:25:25

                                                    Tiens, voila ce que ça donne, chez moi ...

                                                    http://hpics.li/01920dc

                                                    Le seul truc, pour compiler, il faut prendre gcc de base ... Avec les options de compilation assez laxiste ...

                                                    En tout cas, merci ^^

                                                    -
                                                    Edité par @che 27 avril 2013 à 13:26:46

                                                    • Partager sur Facebook
                                                    • Partager sur Twitter

                                                    🍊 - Étudiant - Codeur en C | Zeste de Savoir apprenez avec une communauté | Articles  - ♡ Copying is an act of love.

                                                      27 avril 2013 à 14:06:20

                                                      @che

                                                      Il ne manque pas un petit #include <stdio.h> pour le printf ?

                                                      En tout cas chez moi  ça ne compile pas sans.

                                                      Bien joué  quand même, ça c'est du conci :)

                                                      -
                                                      Edité par sylv1pdt 27 avril 2013 à 14:07:35

                                                      • Partager sur Facebook
                                                      • Partager sur Twitter
                                                        27 avril 2013 à 14:24:36

                                                        ^^ Avec des options de compilation pas trop exigentes, gcc est capable de linker tout seul :)
                                                        Il m'affiche bien un avertissement par-contre ...
                                                        Merci :3
                                                        • Partager sur Facebook
                                                        • Partager sur Twitter

                                                        🍊 - Étudiant - Codeur en C | Zeste de Savoir apprenez avec une communauté | Articles  - ♡ Copying is an act of love.

                                                          27 avril 2013 à 14:42:01

                                                          v4vx a écrit:

                                                          Kokopak a écrit:

                                                          Eskimon a écrit:

                                                          Bon je reconnais, c'est pas vraiment une animation (je crée juste un invader) mais il y a pas moyen de faire un sleep en BF...

                                                          Par contre au niveau taille du code, je m'en sors honorablement avec 183 octets :)

                                                          v4vx a écrit:

                                                          Totalisant en tout 214 octets ! (Hé oui, les fonction en Ti-BASIC sont du Byte-Code:D )
                                                          (Si quelqu'un arrive à faire moins lourd, je dis chapeau :o )



                                                          Tu pourras dire chapeau à Eskimon :D.


                                                          Lui je lui tire mon chapeau plus pour le BF, mais malheureusement (limite du BF), par de random :x

                                                          Merci ^^ mais oui pour mon code BF je suis hors sujet, c'était juste pour la performance :D , mais comme dit plus haut, les limites du BF m’empêche de faire une vrai animation (et du coup si c'était possible je n'aurais jamais fait si peu d'octets).

                                                          Mais je tiens à rester dans le cadre avec mon code Arduino ^^



                                                          -
                                                          Edité par Eskimon 27 avril 2013 à 14:44:42

                                                          • Partager sur Facebook
                                                          • Partager sur Twitter

                                                          Retrouvez moi sur mon blog et ma chaine Youtube !

                                                            27 avril 2013 à 16:05:33

                                                            Après mon Invader en Java, nouvelle contribution plus originale de ma part, en Axe.
                                                            C'est un langage compilé pour Ti-83+/84+ (et SE) (il faut avoir une mémoire Flash pour exécuter le compilateur Axe). Le langage est donc beaucoup plus rapide que le Ti-Basic, tout en restant plus lisible que l'ASM. Cependant, il est assez bas niveau, il est fréquent de gérer soi-même la mémoire, et travailler avec de l'hexadécimal et du binaire.
                                                            J'affiche donc un Invader en 14*12. A chaque changement de position, je fais une rapide animation de 20 frames qui le fait apparaître n'importe où sur l'écran (voir photo et GIF en bas du code). Les yeux sont affichés en nuance de gris.
                                                            Bref, voilà le code (qui serait encore moins lisible que ça si j'avais cherché à optimiser) :
                                                            .INVADER
                                                            
                                                            [000000000C0C3F3F]→Pic1Bo1
                                                            [00000000C0C0F0F0]→Pic1Bo2
                                                            [33333333FFFFCCCC]→Pic1Bo3
                                                            [30303030FCFCCCCC]→Pic1Bo4
                                                            [C0C0000000000000]→Pic1Eye
                                                            
                                                            150→T
                                                            Repeat getKey(15)
                                                            T++
                                                            
                                                            If T>150
                                                            ClrDraw
                                                            ClrDrawʳ
                                                            Inva()
                                                            End
                                                            
                                                            T>170?0→T
                                                            DispGraphʳ
                                                            End
                                                            
                                                            Lbl Inva
                                                            rand^75→X
                                                            rand^48→Y
                                                            Pt-On(X,Y,Pic1Bo1)
                                                            Pt-On(X+8,Y,Pic1Bo2)
                                                            Pt-On(X,Y+8,Pic1Bo3)
                                                            Pt-On(X+8,Y+8,Pic1Bo4)
                                                            
                                                            Y→Z
                                                            rand^2?Y+2→Y
                                                            Pt-On(X+4,Y+8,Pic1Eye)ʳ
                                                            
                                                            Y>Z?rand^2?Y-2→Y
                                                            Pt-On(X+8,Y+8,Pic1Eye)ʳ
                                                            Return


                                                            -
                                                            Edité par mogolecho 27 avril 2013 à 16:37:15

                                                            • Partager sur Facebook
                                                            • Partager sur Twitter
                                                              27 avril 2013 à 16:36:08

                                                              Voici ma petite part d'Invader, j’espère qu'elle vous plaira :

                                                              http://nchristophe.magix.net/public/Invader/

                                                              Elle est réalisé en javascript en utilisant la balise canvas.

                                                              L'Invader est redessiné toute les 3 secondes avec une position et une couleur aléatoire, rien de plus compliqué.

                                                              Voici mon code Javascript :

                                                              document.getElementById('canvas').width = window.innerWidth; // Canvas avec taille maximum
                                                              document.getElementById('canvas').height = window.innerHeight;
                                                              window.onresize = function() {
                                                              	document.getElementById('canvas').width = window.innerWidth;
                                                              	document.getElementById('canvas').height = window.innerHeight;
                                                              }
                                                              var context = document.getElementById('canvas').getContext('2d');
                                                              var invader = [0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1]; // Invader pixel par pixel
                                                              function draw() {
                                                              	context.clearRect(0, 0, window.innerWidth, window.innerHeight)
                                                              	var x = Math.floor(Math.random() * (window.innerWidth - 518)); // Position aléatoire
                                                              	var y = Math.floor(Math.random() * (window.innerHeight - 320));
                                                              	context.fillStyle = '#' + (Math.random() * 0x313131 + 0xaaaaaa | 0).toString(16); // Couleur aléatoire avec une certaine teinte
                                                              	for (var i = 0; i < invader.length; i++) {
                                                              		if (invader[i]) {
                                                              			context.fillRect(i * 54 - Math.floor(i / 7) * 378 + x, Math.floor(i / 7) * 54 + y, 50, 50); // Carré
                                                              		}
                                                              	}
                                                              	context.fillStyle = '#000000';
                                                              	context.fillRect(2 * 54 + x, 2 * 54 + y + Math.floor(Math.random() * 2) * 54, 50, 50); // On dessine les yeux
                                                              	context.fillRect(4 * 54 + x, 2 * 54 + y + Math.floor(Math.random() * 2) * 54, 50, 50);
                                                              }
                                                              draw();
                                                              setInterval(draw, 3000); // On répète toutes les 3 secondes



                                                              • Partager sur Facebook
                                                              • Partager sur Twitter

                                                              [Atelier] Fond animé Space Invaders

                                                              × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                                              × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                                              • Editeur
                                                              • Markdown