// Converting SRTM ASCII terrain matrices into PNG graphic files
// (C) 2010 Jörg 'Yadgar' Bleimann
// Non-commercial use is free; any commercial usage needs written authorization by the copyright owner

#declare xdim=1200;
#declare ydim=1200;
#declare i=0;
#declare h=0;

#declare deadsea=422;
#declare everest=8848;
#declare rng=everest+deadsea;

#fopen srtm "../auxiliary/S44E147_S44E148_patched.txt" read
#while (defined(srtm))
  #read (srtm, h)
  box
  {
    0, <1, 1, 0.001>
    translate <mod(i,xdim), div(i,xdim), 0>

    texture
    {
      #if (h=-9999)
	pigment { color rgb <0, 0, 1> }
      #else
	#declare r_raw=(h+deadsea)/rng*255;
	#declare r=int(r_raw);
	#declare g_raw=(r_raw-r)*255;
	#declare g=int(g_raw);
	pigment { color rgb <r,g,0>/255 }
      #end
      finish { ambient 1 }
    }
  }
  #declare i=i+1;
#end
#fclose srtm

camera
{
  orthographic
  up <0, ydim, 0>
  right <xdim, 0, 0>
  location <xdim/2, ydim/2, -10>
  look_at <xdim/2, ydim/2, 0>
}