|
|
I found the Perl::GD module convenient for generating a height field. For example:
#! /usr/bin/perl
use strict;
use GD::Simple;
# create a new image
my npoints = 256;
my $image = GD::Simple->new($npoints, $npoints);
# .. (clipped) a 2-d array f is populated with values, with maximal value fmax
for my $nx ( 0 .. $npoints - 1) {
for my $ny ( 0 .. $npoints - 1) {
my $f = int(255 * $f[$nx]->[$ny] / $fmax);
my $color = $image->colorExact($f, $f, $f);
$color = $image->colorAllocate($f, $f, $f)
if ($color < 0);
die
if ($color < 0);
$image->setPixel($nx,$ny,$color);
}
}
open FOUT, ">heightfield.png"
or die;
print FOUT $image->png;
Post a reply to this message
|
|