#!/usr/bin/perl -w use strict; use Config; use constant bits => $Config{randbits}; use constant b2 => int(bits/2); use constant b1 => bits - b2; #sub rand2 {return rand 1, rand 1} sub rand2 { my $r = int rand(2**bits); my $r2 = $r >> b1; return((($r & ((1< $x1, G1 => $y1, B1 => $z1, R2 => $x2, G2 => $y2, B2 => $z2}; use constant color_noise => $ARGV[0]; use constant color_base => 128; sub noise_color () { my ($r1, $r2) = (normal_dist, normal_dist); int(0.5 + color_base + color_noise * R1 * $r1 + color_noise * R2 * $r2), int(0.5 + color_base + color_noise * G1 * $r1 + color_noise * G2 * $r2), int(0.5 + color_base + color_noise * B1 * $r1 + color_noise * B2 * $r2) } use constant {w => 200, h => 400}; use GD; die "Usage: $0 COLORNOISE\n" unless @ARGV == 1; my $im = GD::Image->newTrueColor(2*w, h); my $black = $im->colorAllocate(0,0,0); for my $x (0..w-1) { for my $y (0..h-1) { my (@c) = noise_color; #print "@c\n"; my $i = $im->colorExact(@c); $i = $im->colorAllocate(@c) unless $i >= 0; $im->setPixel($x, $y, $i); my $g = int(0.5 + color_base + color_noise/(h-1)*$y*normal_dist); $i = $im->colorExact($g, $g, $g); $i = $im->colorAllocate($g, $g, $g) unless $i >= 0; $im->setPixel($x+w, $y, $i); } } for my $frac (0..10) { my $h = int(0.5 + (h - 1) * $frac/10); $im->line(int(w*1.9), $h, 2*w-1, $h, $black); } binmode STDOUT; print STDOUT $im->png;