POV-Ray : Newsgroups : povray.advanced-users : height field generation : height field generation Server Time
3 Jul 2024 06:19:08 EDT (-0400)
  height field generation  
From: Dan Connelly
Date: 30 Sep 2008 00:24:01
Message: <48e1a9e1$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.