simbols); switch($param){ case \"red\": $this->palette=\"red\"; break; case \"blue\": $this->palette=\"blue\"; break; case \"green\": $this->palette=\"green\"; break; case \"warhol1\": $this->palette=array(); for($i=0;$i<$size/2;$i++) $this->palette[$i]=array(10+$i*(320/$size),255,255); for($i=$size/2;$i<$size;$i++) $this->palette[$i]=array(255,255,10+($i-($size/2))*(320/$size)); break; case \"warhol2\": $this->palette=array(); for($i=0;$i<$size/2;$i++) $this->palette[$i]=array(10+$i*(320/$size),255,255); for($i=$size/2;$i<$size;$i++) $this->palette[$i]=array(255,155,10+($i-($size/2))*(320/$size)); break; case \"warhol3\": $this->palette=array(); for($i=0;$i<$size/2;$i++) $this->palette[$i]=array(255,10+$i*(320/$size),255); for($i=$size/2;$i<$size;$i++) $this->palette[$i]=array(255,255,10+($i-($size/2))*(320/$size)); break; case \"warhol4\": $this->palette=array(); for($i=0;$i<$size/2;$i++) $this->palette[$i]=array(10+$i*(320/$size),10+$i*(320/$size),255); for($i=$size/2;$i<$size;$i++) $this->palette[$i]=array(255,155,10+($i-($size/2))*(320/$size)); break; case \"warhol5\": $this->palette=array(); for($i=0;$i<$size/2;$i++) $this->palette[$i]=array(255,10+$i*(320/$size),10+$i*(320/$size)); for($i=$size/2;$i<$size;$i++) $this->palette[$i]=array(10+($i-($size/2))*(320/$size),255,10+($i-($size/2))*(320/$size)); break; //Aqui se deben incluir paletas personalizadas por el usuario //paletas personalizadas case \"personal1\": $this->palette=array(50,65,80,95,110,125,145,160,175,195,210,220,235,240,245,250); break; case \"personal2\": $this->palette=array(array(0,0,155), array(20,20,165), array(60,40,185), array(140,10,200), array(100,100,200), array(150,150,250), array(180,180,255), array(200,100,100), array(255,100,100), array(255,150,100), array(255,130,130), array(255,120,120), array(255,190,140), array(240,200,150), array(245,220,150), array(250,240,150) ); //paleta a color break; //paleta por defecto default: $this->palette=\"\"; break; } } } //clase para crear diccionarios de simbolos class dicclass{ var $simbols; function dicclass($param){ switch($param){ //Aqui diccionarios personalizados case \"ejemplo1\": $this->simbols=array(\'x\',\'v\',\'o\',\'p\',\'Q\',\'U\',\'A\',\'-\',\'0\',\'Y\',\'d\',\'s\',\'1\',\'3\',\'4\',\'4\'); break; //dicionario por defecto default: $this->simbols=array(\'M\',\'N\',\'H\',\'#\',\'Q\',\'U\',\'A\',\'D\',\'0\',\'Y\',\'2\',\'$\',\'%\',\'+\',\'.\',\' \'); break; } } } //clase que crea un cronometro class crono{ var $timer_ini; function _start(){ $this->timer_ini=$this->microtime_float(); } function _reset(){ $this->timer_ini=$this->microtime_float(); } function _getTime(){ return ($this->microtime_float()-$this->timer_ini); } function _print(){ echo \"Timer: \".$this->_getTime(); } function microtime_float() { list($useg, $seg) = explode(\" \", microtime()); return ((float)$useg + (float)$seg); } } //super-clase del motor de renderizado, abre el archivo y incorpora metodos para ver la eficiencia de los motores de render //Nota: se han probado el motor de lineas verticales y el de cuadrados con mascara y despues de ver el resultado de eficiencia //se ha optado por incorporar el de lineas horizontales class engine{ var $gestor; var $size_X; var $size_Y; //Constructor de superclase function engine($source){ $this->gestor=file($source) or die(\"Cannot open file\"); if(($tmp1=strpos($this->gestor[0], \"\\n\"))==FALSE) $tmp1=strlen($this->gestor[0]); if(($tmp2=strpos($this->gestor[0], \"\\r\"))==FALSE) $tmp2=strlen($this->gestor[0]); $tmp3=($tmp1>$tmp2)?$tmp2:$tmp1; $this->size_X=$tmp3; //obviamos \\n y/o \\r $this->size_Y=count($this->gestor); } //muestra el numero de poligonos que se renderizan con el motor lineal horizontal function getPols_hor_engine(){ $n=0; for($_y=0;$_ygestor);$_y++){ for($_x=0;$_xgestor[$_y]);$_x++){ $c=$this->gestor[$_y][$_x]; $size=0; while($c==$this->gestor[$_y][++$_x]&&$_xgestor[$_y])) $size++; $_x--; $n++; } } return $n; } //muestra el numero de poligonos que se renderizan con el motor lineal vertical function getPol_ver_engine(){ $n=0; for($_x=0;$_xgestor[0]);$_x++){ $patron=-1; for($_y=0;$_ygestor);$_y++){ $c=substr($this->gestor[$_y],$_x,1); if($patron==-1){ $patron=$c; $n++; } if($patron!=$c){ $n++; } $patron=$c; } } return $n; } } class cg_engine extends engine{ var $img; var $color; var $dictionary; var $timer; //Constructor del motor de renderizado //Recibe como parámetros: cg_engine(file_name,$tabla_de_simbolos,$paleta_de_colores) //Las paletas de colores pueden ser generadas con la clase palclass o bien a mano siguiendo los pasos establecidos en dicha clase //Ademas si $paleta_de_colores se inicia a \"blue\",\"red\" o \"green\" se utilizan las paletas de colores puros //Si se inicia a \"\" se utiliza la paleta por defecto que es la de fondo de grises function cg_engine($source,$_dic,$pal){ $this->timer=new crono(); //creamos crono $this->timer->_start(); //arrancamos el crono parent::engine($source); //constructor de la superclase $this->img = @imageCreateTrueColor($this->size_X, $this->size_Y) or die(\"Cannot Initialize new GD image stream\"); //diccionario de simbolos $this->dictionary=$_dic->simbols; //paleta por defecto B&W $this->ini_pal($pal->palette); imagefill($this->img, 0, 0, $this->color[0]); //color de fondo de paleta } //iniciamos paleta function ini_pal($param){ $this->color=array(); for($i=0;$idictionary);$i++){ if($i==0) $tmp=0; else $tmp=((count($this->dictionary)+1)*$i); switch($param){ case \"red\": $this->color[$i]= imageColorAllocate($this->img, 255, $tmp, $tmp); break; case \"green\": $this->color[$i]= imageColorAllocate($this->img,$tmp , 255, $tmp); break; case \"blue\": $this->color[$i]= imageColorAllocate($this->img,$tmp ,$tmp, 255); break; default: if(is_array($param)){ if(count($this->color)==0) foreach ($param as $key => $value) if(count($value)==1) $this->color[$key]= imageColorAllocate($this->img,$value,$value,$value); else $this->color[$key]= imageColorAllocate($this->img,$value[0] ,$value[1],$value[2]); else break; } else $this->color[$i]= imageColorAllocate($this->img,$tmp ,$tmp,$tmp); } } } //Realiza el render por defecto con crono function render(){ $this->render_nc(); //mostramos crono imagestring ($this->img, 2, 0, 0, $this->timer->_getTime().\" s.\", 205 ); } //Realiza el render por defecto sin crono function render_nc(){ $fondo=$this->dictionary[0]; foreach ($this->gestor as $_y => $lineas){ $_x=0; while($_x<$this->size_X){ while($lineas[$_x++]==$fondo){}//no se procesa el fondo de paleta $c=$lineas[--$_x]; $_x_old=$_x; while($c==$lineas[++$_x]/*&&$_x<$this->size_X*/){} if($_x>($_x_old+1)) imageline($this->img, $_x_old, $_y, $_x-1, $_y, $this->color[array_search($c, $this->dictionary)]); else imagesetpixel($this->img, $_x_old, $_y,$this->color[array_search($c, $this->dictionary)]); } } } //genera archivo temporal de imagen function getImage(){ header(\"Content-type: image/png\"); //generamos la imagen imagepng($this->img); //liberamos la memoria ocupada por la imagen imagedestroy($this->img); } } ?> render_nc()):($ob->render()); else $ob->render(); //renderiza sin crono $ob->getImage(); //genera png } ?>