imagecolorallocate: klappt nur einmal
glan
- php
Hallo,
ich will mit PHP mehrere Farben mittels imagesetpixel zufällig in eine Grafik einfügen...
Der Code:
<?php
header('Content-Type: image/gif');
$bild = imagecreate(100, 100);
// Generiert 20 zufällig aussehende Zufallspixel:
for($h = 0; $h != 20; ++$h)
{
$farbe = imagecolorallocate($bild, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($bild, rand(0, 99), rand(0, 99), $farbe);
}
// Der folgende Block funzt einfach nimmer:
for($h = 0, $r = 0, $g = 0, $b = 0; $h != 100; ++$h, ++$r, ++$g, ++$b)
{
$farbe2 = imagecolorallocate($bild, $r, $g, $b);
imagesetpixel($bild, rand(0, 99), rand(0, 99), $farbe2);
}
imagegif($bild);
imagedestroy($bild);
?>
Warum funktionier das in der 2. For-Schleife nimmer? Ideen?
Danke im Vorraus... :D
MfG
Moin!
// Der folgende Block funzt einfach nimmer:
for($h = 0, $r = 0, $g = 0, $b = 0; $h != 100; ++$h, ++$r, ++$g, ++$b)
{
$farbe2 = imagecolorallocate($bild, $r, $g, $b);
imagesetpixel($bild, rand(0, 99), rand(0, 99), $farbe2);
}
Das liegt aber viel eher an der falschen for-Syntax, als am imagecolorallocate.
Warum funktionier das in der 2. For-Schleife nimmer? Ideen?
Mach die for-Schleife mal "vorschriftsgemäß". Das meiste dort brauchst du nicht IM for-Statement, sondern dahinter.
- Sven Rautenberg