perl中画图的问题
我想用perl画一张随机颜色的图,怎么结果老是同一种颜色呢?
#use image::Magick;use GD;# Create a new image$im = new GD::Image(100,100);# Allocate some colors#$white = $im->colorAllocate(255,255,255);#$black = $im->colorAllocate(0,0,0);#$red = $im->colorAllocate(255,0,0);#$blue = $im->colorAllocate(0,0,255);#print $white."\n";#print $black."\n";#print $red."\n";#print $blue."\n";# Make the background transparent and interlaced#$im->transparent($white);#$im->interlaced('false');my $color;$color = $im->colorAllocate(100,100,100);foreach(0..100){ $i =$_; foreach(0..100) { $im->colorDeallocate($color); $color = $im->colorAllocate(int(rand(256)),int(rand(256)),int(rand(256))); $im->setPixel($_,$i,$color); print $color."\n"; $im->setPixel($_,$i,$color);}}# Open a file for writingopen(PICTURE, ">picture.png") or die("Cannot open file for writing");# Make sure we are writing to a binary streambinmode PICTURE;# Convert the image to PNG and print it to the file PICTUREprint PICTURE $im->png;close PICTURE;if( (-e "picture.png")){ system("kview picture.png"); system("rm picture.png");}