1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
<?php
class iso
{
var $matrice = false;
var $img = false;
var $resolution = 5;
var $largeur = 100;
var $hauteur = 100;
function iso()
{
$this->img = imagecreatetruecolor($this->largeur * $this->resolution, $this->hauteur * $this->resolution);
$this->matrice = array();
for($i=0;$i<$this->largeur;$i++)
{
$this->matrice[] = array();
for($j=0;$j<$this->hauteur;$j++)
{
//$this->matrice[$i][$j] = $j > 5 && $j < 15 && $i > 5 && $i < 15 ? 10 : 1; //mt_rand(1, 10);
//$this->matrice[10][10] = 1;
$this->matrice[$i][$j] = mt_rand(1, 10);
}
}
}
function DrawPetitCarre($x , $y, $taille, $hg, $hd, $bg, $bd, $r, $g, $b)
{
$color = imagecolorallocate($this->img, $r, $g, $b);
$test = ($hg ? 1 : 0).($hd ? 1 : 0).($bg ? 1 : 0).($bd ? 1 : 0);
$demi = $taille / 2;
switch($test)
{
case '0000':break;
case '0001': imageline($this->img, $x + $demi, $y + $taille, $x + $taille, $y + $demi, $color);break;
case '0010': imageline($this->img, $x, $y + $demi, $x + $demi, $y + $taille, $color);break;
case '0011': imageline($this->img, $x, $y + $demi, $x + $taille, $y + $demi, $color);break;
case '0100': imageline($this->img, $x + $demi, $y, $x + $taille, $y + $demi, $color);break;
case '0101': imageline($this->img, $x + $demi, $y, $x + $demi, $y + $taille, $color);break;
case '0110': imageline($this->img, $x, $y + $demi, $x + $demi, $y, $color);imageline($this->img, $x + $demi, $y + $taille, $x + $taille, $y + $demi, $color);break;
case '0111': imageline($this->img, $x, $y + $demi, $x + $demi, $y , $color);break;
case '1000': imageline($this->img, $x, $y + $demi, $x + $demi, $y, $color);break;
case '1001': imageline($this->img, $x + $demi, $y, $x + $taille, $y + $demi, $color);imageline($this->img, $x, $y + $demi, $x + $demi, $y + $taille, $color);break;
case '1010': imageline($this->img, $x + $demi, $y, $x + $demi, $y + $taille, $color);break;
case '1011': imageline($this->img, $x + $demi, $y, $x + $taille, $y + $demi, $color);break;
case '1100': imageline($this->img, $x, $y + $demi, $x + $taille, $y + $demi, $color);break;
case '1101': imageline($this->img, $x + $demi, $y + $taille, $x , $y + $demi, $color);break;
case '1110': imageline($this->img, $x + $demi, $y + $taille, $x + $taille , $y + $demi, $color);break;
case '1111':break;
}
}
function Render()
{
$val = 5;
$matrice = $this->matrice;
for($val=1;$val<10;$val+=4)
{
for($i=0.5;$i<$this->hauteur-1;$i++)
{
for($j=0.5;$j<$this->largeur-1;$j++)
{
$this->DrawPetitCarre(($j*$this->resolution) + ($this->resolution/2) , ($i * $this->resolution) + ($this->resolution / 2), $this->resolution,
($this->matrice[floor($j)][floor($i)] < $val ? 1 : 0),
($this->matrice[ceil($j)][floor($i)] < $val ? 1 : 0),
($this->matrice[floor($j)][ceil($i)] < $val ? 1 : 0),
($this->matrice[ceil($j)][ceil($i)] < $val ? 1 : 0),
$val == 5 ? 255 : 0, $val == 9 ? 255 : 0, $val == 1 ? 255 : 0
);
}
}
}
}
function HtmlRenderMatrice()
{
$texte = '<style>td{border:1px solid #000000;text_align="center"}</style><table style="border-collapse:collapse;">';
foreach($this->matrice as $keyx => $valx)
{
$texte .= '<tr>';
foreach($valx as $keyy => $valy)
$texte .= '<td>'.$valy.'</td>';
$texte .= '</tr>';
}
$texte .= '</table>';
return $texte;
}
}
$iso = new iso();
$iso->Render();
header('Content-type: image/jpg');
imagejpeg($iso->img);
//echo $iso->HtmlRenderMatrice();
?> |
Partager