Graphics-PLplot

 view release on metacpan or  search on metacpan

t/x08.t  view on Meta::CPAN

}

my @y;
for my $i (0..(YPTS-1) ) {
  $y[$i] = ($i - (YPTS/2)) / (YPTS/2);
  $y[$i] += 0.5 if $rosen;
}

for my $i (0..(XPTS-1)) {
  my $xx = $x[$i];
  for my $j (0..(YPTS-1)) {
    my $yy = $y[$j];
    if ($rosen) {
      $z->[$i][$j] = (1-$xx)**2 + (100 * ($yy-($xx*$xx))**2);
      # The log argument may be zero for just the right grid.
      if ($z->[$i][$j] > 0 ) {
	$z->[$i][$j] = log($z->[$i][$j]);
      } else {
	$z->[$i][$j] = -5;
      }
    } else {
      my $r = sqrt( $xx*$xx + $yy * $yy);
      $z->[$i][$j] = exp(-$r * $r) * cos(2 * pi * $r);
    }
  }
}

my ($zmin, $zmax ) = pl_MinMax2dGrid( $z );
my $step = ($zmax-$zmin)/(LEVELS+1);

my @clevel = map { $zmin + $step + ($_*$step) } (0..(LEVELS-1));

pllightsource(1,1,1);

plspause(0);
for my $k (0..1) {
  for my $ifshade ( 0.. 3 ) {
    pladv(0);
    plvpor(0.0, 1.0, 0.0, 0.9);
    plwind(-1.0, 1.0, -0.9, 1.1);
    plcol0(3);
    plmtex("t", 1.0, 0.5, 0.5, $title[$k]);
    plcol0(1);
    if ($rosen) {
      plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, $zmin, $zmax, $alt[$k], $az[$k]);
    } else {
      plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, $zmin, $zmax, $alt[$k], $az[$k]);
    }
    plbox3("bnstu", "x axis", 0.0, 0,
	   "bnstu", "y axis", 0.0, 0,
	   "bcdmnstuv", "z axis", 0.0, 0);
    plcol0(2);

    if ($ifshade == 0) { # diffuse light surface plot
      cmap1_init(1);
      plsurf3d(\@x, \@y, $z, 0, []);
    } elsif ($ifshade == 1) { # magnitude colored plot
      cmap1_init(0);
      plsurf3d(\@x, \@y, $z, MAG_COLOR, []);
    } elsif ($ifshade == 2) { # magnitude colored plot with faceted squares
      plsurf3d(\@x, \@y, $z, MAG_COLOR | FACETED, []);
    } else {                 #  magnitude colored plot with contours
      plsurf3d(\@x, \@y, $z, MAG_COLOR | SURF_CONT | BASE_CONT, \@clevel);
    }
    plflush();
    select undef,undef,undef,$sleep;
  }
}

plend();
exit;


# Initialise color map 1 in HLS space

sub cmap1_init {
  my $gray = shift;

  my (@i,@h,@l,@s);

  $i[0] = 0; # Left boundary
  $i[1] = 1; # Right boundary

  if ($gray) {
    $h[0] = 0.0;         # hue -- low: red (arbitrary if s=0)
    $h[1] = 0.0;         # hue -- high: red (arbitrary if s=0)

    $l[0] = 0.5;         # lightness -- low: half-dark
    $l[1] = 1.0;         # lightness -- high: light

    $s[0] = 0.0;         # minimum saturation
    $s[1] = 0.0;         # minimum saturation
  } else {
    $h[0] = 240;         # blue -> green -> yellow ->
    $h[1] = 0;           #  -> red
    $l[0] = 0.6;
    $l[1] = 0.6;
    $s[0] = 0.8;
    $s[1] = 0.8;
  }

  plscmap1n(256);
  plscmap1l(0, \@i, \@h, \@l, \@s, []);
}



( run in 0.877 second using v1.01-cache-2.11-cpan-e1769b4cff6 )