#!/usr/bin/perl
#
# Compute values of a periodic function which looks
#    like mountain peaks in the distance
#
# MWR 2/8/2019

use POSIX;

$debug = 1;

$amplitude = 1.0;
$period = 4.0;

$start_x = -50;
$end_x = 50;
$dx = 0.01;

for ($x = $start_x; $x <= $end_x; $x += $dx) {

  $z = ($x/$period) - floor($x/$period);

  if ($z < 0.25) {
    $val = 0.0;
  }
  elsif ($z < 0.50) {
    $val = ($amplitude*4.0)*($z - 0.25);
  }
  elsif ($z < 0.75) {
    $val = ($amplitude*4.0)*(0.75 - $z);
  }
  else {
    $val = 0.0;
  }


  printf " x %12.5f  z %12.5f   val %12.5f \n", $x, $z, $val;


}

exit 0;
