|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> I found the Perl::GD module convenient for generating a height field.
If you have a function to generate the height
field, you can also use it in SDL directly:
#declare npoints = 512;
#declare f = function {0.1+0.1*sin(x*20)};
#declare fmax = 0.2;
height_field
{
function npoints, npoints {f(x,0,y)/fmax}
}
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Christian Froeschlin wrote:
>> I found the Perl::GD module convenient for generating a height field.
>
> If you have a function to generate the height
> field, you can also use it in SDL directly:
>
> #declare npoints = 512;
> #declare f = function {0.1+0.1*sin(x*20)};
> #declare fmax = 0.2;
>
> height_field
> {
> function npoints, npoints {f(x,0,y)/fmax}
> }
Thanks!
A disadvantage of the Perl GD module is I can't figure out how to generate 16-bit PNG
with it, which is a real issue, even with "smooth". The advantage, of course, is you
needn't reevaluate the function each time the code is executed, depending on the
function complexity.
Dan
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Dan Connelly wrote:
> The advantage, of course, is you needn't reevaluate the function each
> time the code is executed, depending on the function complexity.
You can also use a POV script to generate a 16-bit PNG
based on a function, either by defining a function pigment
or by rendering the heigth_field itself using hf_gray_16.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> A disadvantage of the Perl GD module is I can't figure out how to generate
> 16-bit PNG with it, which is a real issue, even with "smooth". The advantage,
> of course, is you needn't reevaluate the function each time the code is
> executed, depending on the function complexity.
I recommend the ppm or, in the case of heightfields, pgm format instead of png.
It is very easy to create, with as many bits as you want.
Povray does support ppm, but I am unsure whether bit-depths higher than 16
are supported. Also, I am unsure if pgm is supported, but you can always use
ppm im case it is not.
See http://netpbm.sourceforge.net/doc/#formats
Best regards,
Mark Weyer
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|