PDA

Vollstndige Version anzeigen : imagefunktion mit schleife


paschy`
04-06-2004, 16:01
Hallo ich habe folgendes problem:

ich habe hier diesen code:


<?
function insel($pic,$c,$x1,$y1,$x2,$y2)
{
if(!$c){
$r = 0;
$g = 0;
$b = 0;
}
else {
$c = eregi_replace("#","",$c);
$r = hexdec(substr($c,0,2));
$g = hexdec(substr($c,2,2));
$b = hexdec(substr($c,4,2));
}
$rand=ImageColorAllocate($pic,133,133,133);
$farbe=ImageColorAllocate($pic,$r,$g,$b);
ImageFilledRectangle($pic,$x1-1,$y1-1,$x2+1,$y2+1,$rand);
ImageFilledRectangle($pic,$x1,$y1,$x2,$y2,$farbe);
}
$pic=ImageCreate(800,800);
$bg=ImageColorAllocate($pic,200,200,200);
//insel($pic,FFFFFF,451,86,461,96);
for($i;$i<=5;$i++)
{

insel($pic,AABBCC,$i*73+30,30,$i*73+40,40);
insel($pic,AABBCC,$i*73+44,30,$i*73+54,40);
insel($pic,AABBCC,$i*73+58,30,$i*73+68,40);
insel($pic,AABBCC,$i*73+72,30,$i*73+82,40);
insel($pic,AABBCC,$i*73+86,30,$i*73+96,40);

insel($pic,AABBCC,$i*73+30,44,$i*73+40,54);
insel($pic,AABBCC,$i*73+44,44,$i*73+54,54);
insel($pic,AABBCC,$i*73+58,44,$i*73+68,54);
insel($pic,AABBCC,$i*73+72,44,$i*73+82,54);
insel($pic,AABBCC,$i*73+86,44,$i*73+96,54);

insel($pic,AABBFF,$i*73+30,58,$i*73+40,68);
insel($pic,AABBCC,$i*73+44,58,$i*73+54,68);
insel($pic,AABBCC,$i*73+58,58,$i*73+68,68);
insel($pic,AABBCC,$i*73+72,58,$i*73+82,68);
insel($pic,AABBCC,$i*73+86,58,$i*73+96,68);

insel($pic,AABBCC,$i*73+30,72,$i*73+40,82);
insel($pic,AABBCC,$i*73+44,72,$i*73+54,82);
insel($pic,AABBCC,$i*73+58,72,$i*73+68,82);
insel($pic,AABBCC,$i*73+72,72,$i*73+82,82);
insel($pic,AABBCC,$i*73+86,72,$i*73+96,82);

insel($pic,AABBCC,$i*73+30,86,$i*73+40,96);
insel($pic,AABBCC,$i*73+44,86,$i*73+54,96);
insel($pic,AABBCC,$i*73+58,86,$i*73+68,96);
insel($pic,AABBCC,$i*73+72,86,$i*73+82,96);
insel($pic,AABBCC,$i*73+86,86,$i*73+96,96);
}

ImagePNG($pic);
ImageDestroy($pic);
?>


und als ergebnis krieg ich folgendes: www.if.qnh.ch/test.php

Jetzt ist meine Frage, warum bei dem 5. Kstchen keine farbe mehr kommt also das rectangle nichmehr gemalt wird?

ich hoff ihr knnt mir helfen

chris17
04-06-2004, 16:26
Hallo,

es liegt an der Initialisierung von $i

for($i=1;$i<=5;$i++)
{

Grsse

chris17

paschy`
04-06-2004, 21:49
aber es geht immernoch nicht so recht:

hab jetzt erstmal schleifen gemacht und nun sieht der code so aus...


<?
function insel($pic,$c,$x1,$y1,$x2,$y2)
{
if(!$c){
$r = 0;
$g = 0;
$b = 0;

}
else {
$c = eregi_replace("#","",$c);
$r = hexdec(substr($c,0,2));
$g = hexdec(substr($c,2,2));
$b = hexdec(substr($c,4,2));
}
$rand=ImageColorAllocate($pic,133,133,133);
$farbe=ImageColorAllocate($pic,$r,$g,$b);
ImageFilledRectangle($pic,$x1-1,$y1-1,$x2+1,$y2+1,$rand);
ImageFilledRectangle($pic,$x1,$y1,$x2,$y2,$farbe);
}

$pic=ImageCreate(850,850);
$bg=ImageColorAllocate($pic,200,200,200);


//insel($pic,FFFFFF,451,86,461,96);

for($y2=1;$y2<=10;$y2++)
{
for($x2=1;$x2<=10;$x2++)
{
for($y1=1;$y1<=5;$y1++)
{
for($x1=1;$x1<=5;$x1++)
{
insel($pic,AABBCC,$x2*77-77+43+$x1*15-15,$y2*77-77+43+$y1*15-15,$x2*77-77+53+$x1*15-15,$y2*77-77+53+$y1*15-15);
}
}
}
}
ImagePNG($pic);
ImageDestroy($pic);
?>


habe also die variablen initialisiert allerdings hat das nich wirklich was gebracht: www.if.qnh.ch/test.php

paschy`
05-06-2004, 20:43
also es muss an der function liegen, die will nich so recht... wenn ich den inhalt der function insel in den main teil lege also die 2 rectangels dort zeichnen lasse, dann geht das alles wunderbar nur mit der function irgendwie nich.. weiss da einer warum das so is?