<?php

function position()
{global $x_pt,$y_pt,$a1,$b1,$c1,$d1,$e1,$f1,$p1,$a2,$b2,$c2,$d2,$e2,$f2,$p2;
global $image,$col2,$a3,$b3,$c3,$d3,$e3,$f3,$p3,$a4,$b4,$c4,$d4,$e4,$f4,$p4;
global $a5,$b5,$c5,$d5,$e5,$f5,$p5,$x_dep,$y_dep;
mt_srand((double)microtime()*1000000);$x_pt2=0;$y_pt2=0;
$lim1=$p1*100;$lim2=$lim1+100*$p2;$lim3=$lim2+100*$p3;$lim4=$lim3+100*$p4;
while ((abs($x_pt-$x_pt2)>0.02)||(abs($y_pt-$y_pt2)>0.02))
{$dep=mt_rand(0,100);$x_pt=$x_pt2;$y_pt=$y_pt2;
if ($dep<=$lim1) {$x_pt2=$a1*$x_pt+$b1*$y_pt+$c1;$y_pt2=$d1*$x_pt+$e1*$y_pt+$f1;}
else
{if ($dep<=$lim2) {$x_pt2=$a2*$x_pt+$b2*$y_pt+$c2;$y_pt2=$d2*$x_pt+$e2*$y_pt+$f2;}
else
{if ($dep<=$lim3) {$x_pt2=$a3*$x_pt+$b3*$y_pt+$c3;$y_pt2=$d3*$x_pt+$e3*$y_pt+$f3;}
else
{if ($dep<=$lim4) {$x_pt2=$a4*$x_pt+$b4*$y_pt+$c4;$y_pt2=$d4*$x_pt+$e4*$y_pt+$f4;}
else
{$x_pt2=$a5*$x_pt+$b5*$y_pt+$c5;$y_pt2=$d5*$x_pt+$e5*$y_pt+$f5;}}}}
imagesetpixel($image,20+$x_dep+50*$x_pt2,580-$y_dep-50*$y_pt2,$col2); 
}}

function faire_image($nbessais)
{global $x_pt,$y_pt,$num,$image,$col2;
$image=imagecreate(600,600);
$col_fond = ImageColorAllocate($image, 200,200,200);
$col1 = ImageColorAllocate($image,255,255,255);
$col2 = ImageColorAllocate($image,255,0,0);
$col3 = ImageColorAllocate($image,0,255,0);
imagefill($image,0, 0,$col_fond);
imagefilledrectangle ($image,20,20,580,580,$col1);
for ($j=1;$j<=$nbessais;$j++)
{$x_pt=10;$y_pt=10;position();}
ImagePng($image);
}

function faire_page()
{global $nbessais,$a1,$b1,$c1,$d1,$e1,$f1,$p1,$a2,$b2,$c2,$d2,$e2,$f2,$p2;
global $a3,$b3,$c3,$d3,$e3,$f3,$p3,$a4,$b4,$c4,$d4,$e4,$f4,$p4,$x_dep,$y_dep;
global $a5,$b5,$c5,$d5,$e5,$f5,$p5,$option;
echo "<html><body><FONT face='Verdana, Arial' size=2 color='#000080'><center>\n";
echo "IFS: 5 transformations affines et leur probabilité d'être choisie<BR>\n";
echo "ax + by + c -> x et dx + ey + f -> y\n"; 
echo "<form METHOD='GET' ACTION='ifs.php3?option=libre&action=niv&'>\n";
echo "<table border='1' width='100%'>\n";
echo "<tr><td width='17%'><b><center>Transfo</td><td width='11%'><b><center>a</td><td width='11%'><b><center>b</td><td width='11%'><center><b>c</td>\n";
echo "<td width='11%'><b><center>d</td><td width='11%'><b><center>e</td><td width='11%'><b><center>f</td><td width='11%'><b><center>Proba</td><b><td width='6%'>&nbsp;</td></tr>\n";
echo "<tr><td width='17%'><b><center>T1</td><td width='11%'><input type='text' name='a1' size='8' value='".$a1."'></td>\n";
echo "<td width='11%'><input type='text' name='b1' size='8' value='".$b1."'></td>\n";
echo "<td width='11%'><input type='text' name='c1' size='8' value='".$c1."'></td>\n";
echo "<td width='11%'><input type='text' name='d1' size='8' value='".$d1."'></td>\n";
echo "<td width='11%'><input type='text' name='e1' size='8' value='".$e1."'></td>\n";
echo "<td width='11%'><input type='text' name='f1' size='8' value='".$f1."'></td>\n";
echo "<td width='11%'><input type='text' name='p1' size='8' value='".$p1."'></td><td width='6%'>&nbsp;</td></tr>\n";
echo "<tr><td width='17%'><b><center>T2</td><td width='11%'><input type='text' name='a2' size='8' value='".$a2."'></td>\n";
echo "<td width='11%'><input type='text' name='b2' size='8' value='".$b2."'></td>\n";
echo "<td width='11%'><input type='text' name='c2' size='8' value='".$c2."'></td>\n";
echo "<td width='11%'><input type='text' name='d2' size='8' value='".$d2."'></td>\n";
echo "<td width='11%'><input type='text' name='e2' size='8' value='".$e2."'></td>\n";
echo "<td width='11%'><input type='text' name='f2' size='8' value='".$f2."'></td>\n";
echo "<td width='11%'><input type='text' name='p2' size='8' value='".$p2."'></td><td width='6%'>&nbsp;</td></tr>\n";
echo "<tr><td width='17%'><b><center>T3</td><td width='11%'><input type='text' name='a3' size='8' value='".$a3."'></td>\n";
echo "<td width='11%'><input type='text' name='b3' size='8' value='".$b3."'></td>\n";
echo "<td width='11%'><input type='text' name='c3' size='8' value='".$c3."'></td>\n";
echo "<td width='11%'><input type='text' name='d3' size='8' value='".$d3."'></td>\n";
echo "<td width='11%'><input type='text' name='e3' size='8' value='".$e3."'></td>\n";
echo "<td width='11%'><input type='text' name='f3' size='8' value='".$f3."'></td>\n";
echo "<td width='11%'><input type='text' name='p3' size='8' value='".$p3."'></td><td width='6%'>&nbsp;</td></tr>\n";
echo "<tr><td width='17%'><b><center>T4</td><td width='11%'><input type='text' name='a4' size='8' value='".$a4."'></td>\n";
echo "<td width='11%'><input type='text' name='b4' size='8' value='".$b4."'></td>\n";
echo "<td width='11%'><input type='text' name='c4' size='8' value='".$c4."'></td>\n";
echo "<td width='11%'><input type='text' name='d4' size='8' value='".$d4."'></td>\n";
echo "<td width='11%'><input type='text' name='e4' size='8' value='".$e4."'></td>\n";
echo "<td width='11%'><input type='text' name='f4' size='8' value='".$f4."'></td>\n";
echo "<td width='11%'><input type='text' name='p4' size='8' value='".$p4."'></td><td width='6%'>&nbsp;</td></tr>\n";
echo "<tr><td width='17%'><b><center>T5</td><td width='11%'><input type='text' name='a5' size='8' value='".$a5."'></td>\n";
echo "<td width='11%'><input type='text' name='b5' size='8' value='".$b5."'></td>\n";
echo "<td width='11%'><input type='text' name='c5' size='8' value='".$c5."'></td>\n";
echo "<td width='11%'><input type='text' name='d5' size='8' value='".$d5."'></td>\n";
echo "<td width='11%'><input type='text' name='e5' size='8' value='".$e5."'></td>\n";
echo "<td width='11%'><input type='text' name='f5' size='8' value='".$f5."'></td>\n";
echo "<td width='11%'><input type='text' name='p5' size='8' value='".$p5."'></td>\n";
echo "<td width='6%'>&nbsp;</td></tr><tr><td width='17%'><b><center>Point de départ</td>\n";
echo "<td width='11%'><b><center>X :</td>\n";
echo "<td width='11%'><input type='text' name='x_dep' size='8' value='".$x_dep."'></td>\n";
echo "<td width='11%'><b><center>Y :</td>\n";
echo "<td width='11%'><input type='text' name='y_dep' size='8' value='".$y_dep."'></td>\n";
echo "<td width='11%'><b><center>Tracés</td>\n";
echo "<td width='11%'><input type='text' name='nbessais' size='8' value='".$nbessais."'></td>\n";
echo "<td width='11%'>&nbsp;</td><td width='6%'><INPUT TYPE=SUBMIT VALUE='OK'></td></tr>\n";
echo "</table></form>\n";
echo "Exemples : <a href='ifs.php3?option=sierpinski&action=niv&'>Triangle de Sierpinski</a>\n";
echo "&nbsp;&nbsp;<a href='ifs.php3?option=triangle&action=niv&'>Autre triangle</a>\n";
echo "<br>";
echo "<a href='ifs.php3?option=fougere&action=niv&'>Fougère de Barnsley</a>\n";
echo "&nbsp;&nbsp;<a href='ifs.php3?option=buisson&action=niv&'>Branchage</a>\n";
echo "&nbsp;&nbsp;<a href='ifs.php3?option=cristal&action=niv&'>Cristal</a>\n";
echo "&nbsp;&nbsp;<a href='ifs.php3?option=pentagone&action=niv&'>Pentagone</a>\n";
echo "&nbsp;&nbsp;<a href='ifs.php3?option=arbre&action=niv&'>Arbre</a>\n";
echo "<br>";
echo "<BR>";
echo "<img src='ifs.php3?option=".$option."&action=img";
echo "&a1=".$a1."&b1=".$b1."&c1=".$c1."&d1=".$d1."&e1=".$e1."&f1=".$f1."&p1=".$p1;
echo "&a2=".$a2."&b2=".$b2."&c2=".$c2."&d2=".$d2."&e2=".$e2."&f2=".$f2."&p2=".$p2;
echo "&a3=".$a3."&b3=".$b3."&c3=".$c3."&d3=".$d3."&e3=".$e3."&f3=".$f3."&p3=".$p3;
echo "&a4=".$a4."&b4=".$b4."&c4=".$c4."&d4=".$d4."&e4=".$e4."&f4=".$f4."&p4=".$p4;
echo "&a5=".$a5."&b5=".$b5."&c5=".$c5."&d5=".$d5."&e5=".$e5."&f5=".$f5."&p5=".$p5;
echo "&x_dep=".$x_dep."&y_dep=".$y_dep."&nbessais=".$nbessais;
echo "' width='600' height='600'>";
echo "<p>Exemples inspirés de Fractals for the Classroom par Peitgen, Jürgens et Saupe\n";
echo "</body></html>";
}
if (isset($_GET["action"])) $action = $_GET["action"]; else $action = "niv";
if (isset($_GET["option"])) $option = $_GET["option"]; else $option = "fougere";
if (isset($_GET["nbessais"])) $nbessais = $_GET["nbessais"]; 
if (isset($_GET["x_dep"])) $x_dep = $_GET["x_dep"]; 
if (isset($_GET["y_dep"])) $y_dep = $_GET["y_dep"]; 
if (isset($_GET["a1"])) $a1 = $_GET["a1"]; 
if (isset($_GET["b1"])) $b1 = $_GET["b1"]; 
if (isset($_GET["c1"])) $c1 = $_GET["c1"]; 
if (isset($_GET["d1"])) $d1 = $_GET["d1"]; 
if (isset($_GET["e1"])) $e1 = $_GET["e1"]; 
if (isset($_GET["f1"])) $f1 = $_GET["f1"]; 
if (isset($_GET["p1"])) $p1 = $_GET["p1"]; 
if (isset($_GET["a2"])) $a2 = $_GET["a2"]; 
if (isset($_GET["b2"])) $b2 = $_GET["b2"]; 
if (isset($_GET["c2"])) $c2 = $_GET["c2"]; 
if (isset($_GET["d2"])) $d2 = $_GET["d2"]; 
if (isset($_GET["e2"])) $e2 = $_GET["e2"]; 
if (isset($_GET["f2"])) $f2 = $_GET["f2"]; 
if (isset($_GET["p2"])) $p2 = $_GET["p2"]; 
if (isset($_GET["a3"])) $a3 = $_GET["a3"]; 
if (isset($_GET["b3"])) $b3 = $_GET["b3"]; 
if (isset($_GET["c3"])) $c3 = $_GET["c3"]; 
if (isset($_GET["d3"])) $d3 = $_GET["d3"]; 
if (isset($_GET["e3"])) $e3 = $_GET["e3"]; 
if (isset($_GET["f3"])) $f3 = $_GET["f3"]; 
if (isset($_GET["p3"])) $p3 = $_GET["p3"]; 
if (isset($_GET["a4"])) $a4 = $_GET["a4"]; 
if (isset($_GET["b4"])) $b4 = $_GET["b4"]; 
if (isset($_GET["c4"])) $c4 = $_GET["c4"]; 
if (isset($_GET["d4"])) $d4 = $_GET["d4"]; 
if (isset($_GET["e4"])) $e4 = $_GET["e4"]; 
if (isset($_GET["f4"])) $f4 = $_GET["f4"]; 
if (isset($_GET["p4"])) $p4 = $_GET["p4"]; 
if (isset($_GET["a5"])) $a5 = $_GET["a5"]; 
if (isset($_GET["b5"])) $b5 = $_GET["b5"]; 
if (isset($_GET["c5"])) $c5 = $_GET["c5"]; 
if (isset($_GET["d5"])) $d5 = $_GET["d5"]; 
if (isset($_GET["e5"])) $e5 = $_GET["e5"]; 
if (isset($_GET["f5"])) $f5 = $_GET["f5"]; 
if (isset($_GET["p5"])) $p5 = $_GET["p5"]; 

if ($option!="libre")
{switch($option)
{case "fougere":
$a1=0;$b1=0;$c1=0;$d1=0;$e1=0.16;$f1=0;$p1=0.01;
$a2=0.85;$b2=0.04;$c2=0;$d2=-0.04;$e2=0.85;$f2=1.6;$p2=0.85;
$a3=0.2;$b3=-0.26;$c3=0;$d3=0.23;$e3=0.22;$f3=1.6;$p3=0.07;
$a4=-0.15;$b4=0.28;$c4=0;$d4=0.26;$e4=0.24;$f4=0.44;$p4=0.07;
$a5=0;$b5=0;$c5=0;$d5=0;$e5=0;$f5=0;$p5=0;
$x_dep=300;$y_dep=0;$nbessais=100;break;
case "triangle": 
$a1=0;$b1=-0.5;$c1=5;$d1=0.5;$e1=0;$f1=0;$p1=0.33;
$a2=0;$b2=0.5;$c2=5;$d2=-0.5;$e2=0;$f2=5;$p2=0.33;
$a3=0.5;$b3=0;$c3=2.5;$d3=0;$e3=0.5;$f3=5;$p3=0.34;
$a4=0;$b4=0;$c4=0;$d4=0;$e4=0;$f4=0;$p4=0;
$a5=0;$b5=0;$c5=0;$d5=0;$e5=0;$f5=0;$p5=0;
$x_dep=30;$y_dep=0;$nbessais=50;break;
case "sierpinski":
$a1=0.5;$b1=0;$c1=0;$d1=0;$e1=0.5;$f1=0;$p1=0.33;
$a2=0.5;$b2=0;$c2=5;$d2=0;$e2=0.5;$f2=0;$p2=0.33;
$a3=0.5;$b3=0;$c3=0;$d3=0;$e3=0.5;$f3=5;$p3=0.34;
$a4=0;$b4=0;$c4=0;$d4=0;$e4=0;$f4=0;$p4=0;
$a5=0;$b5=0;$c5=0;$d5=0;$e5=0;$f5=0;$p5=0;
$x_dep=30;$y_dep=30;$nbessais=50;break;
case "buisson":
$a1=0.387;$b1=0.430;$c1=2.6;$d1=0.43;$e1=-0.387;$f1=5.22;$p1=0.33;
$a2=0.441;$b2=-0.091;$c2=4.2;$d2=-0.009;$e2=-0.322;$f2=5.1;$p2=0.33;
$a3=-0.468;$b3=0.02;$c3=4;$d3=-0.113;$e3=0.015;$f3=4;$p3=0.34;
$a4=0;$b4=0;$c4=0;$d4=0;$e4=0;$f4=0;$p4=0;
$a5=0;$b5=0;$c5=0;$d5=0;$e5=0;$f5=0;$p5=0;
$x_dep=30;$y_dep=0;$nbessais=50;break;
case "cristal":
$a1=0.255;$b1=0;$c1=3.726;$d1=0;$e1=0.255;$f1=6.74;$p1=0.25;
$a2=0.255;$b2=0;$c2=1.146;$d2=0;$e2=0.255;$f2=2.232;$p2=0.25;
$a3=0.255;$b3=0;$c3=6.306;$d3=0;$e3=0.255;$f3=2.232;$p3=0.25;
$a4=0.37;$b4=-0.642;$c4=6.356;$d4=0.642;$e4=0.37;$f4=-0.06;$p4=0.25;
$a5=0;$b5=0;$c5=0;$d5=0;$e5=0;$f5=0;$p5=0;
$x_dep=30;$y_dep=0;$nbessais=100;break;
case "pentagone":
$a1=0.382;$b1=0;$c1=3.072;$d1=0;$e1=0.382;$f1=6.19;$p1=0.2;
$a2=0.382;$b2=0;$c2=6.033;$d2=0;$e2=0.382;$f2=4.044;$p2=0.2;
$a3=0.382;$b3=0;$c3=0.139;$d3=0;$e3=0.382;$f3=4.044;$p3=0.2;
$a4=0.382;$b4=0;$c4=1.253;$d4=0;$e4=0.382;$f4=0.595;$p4=0.2;
$a5=0.382;$b5=0;$c5=4.920;$d5=0;$e5=0.382;$f5=0.595;$p5=0.2;
$x_dep=30;$y_dep=0;$nbessais=50;break;
case "arbre":
$a1=0.195;$b1=-0.488;$c1=4.431;$d1=0.344;$e1=0.443;$f1=2.452;$p1=0.2;
$a2=0.462;$b2=0.414;$c2=2.511;$d2=-0.252;$e2=0.361;$f2=5.692;$p2=0.2;
$a3=-0.058;$b3=-0.07;$c3=5.976;$d3=0.453;$e3=-0.111;$f3=0.969;$p3=0.2;
$a4=-0.035;$b4=0.07;$c4=4.884;$d4=-0.469;$e4=-0.022;$f4=5.069;$p4=0.2;
$a5=-0.637;$b5=0;$c5=8.562;$d5=0;$e5=0.501;$f5=2.513;$p5=0.2;
$x_dep=30;$y_dep=0;$nbessais=100;break;
}}

if ($action=="img") {faire_image($nbessais);} else {faire_page();}



?>