POV-Ray : Newsgroups : povray.text.scene-files : cells_02.pov : cells_02.pov Server Time
6 Oct 2024 08:41:26 EDT (-0400)
  cells_02.pov  
From: Pete
Date: 28 Sep 2000 19:15:38
Message: <3574.306T1171T11404836PeterC@nym.alias.net>
Here is a small .pov script to fill the landscape
with boxes whose heights are random.  It resembles the
effect of using the megapov "cells" pattern in a height field
or isosurface, except it uses features of the Official
povray 3.1.
        The trick is to use a mesh to generate a block
of "cells", and then tile that to give the appearance of
an infinite field of boxes.

--
/* that cells pigment in megapov looks cool, especially
   when used as an isosurface or high field.  Here we fake
   a cells pigment heightfield by placing a lot of boxes */


global_settings {
  number_of_waves 9
  assumed_gamma 2.4
}


#declare ntsc = false;
#declare rseed = seed(17987092);


#macro rnd_rotate()
  rotate <360 * rand(rseed), 360 * rand(rseed), 360 * rand(rseed)>
#end


#macro rnd_translate()
  translate <4 - 8 * rand(rseed), 4 - 8 * rand(rseed), 4 - 8 * rand(rseed)>
#end


#macro perturb()
  rnd_translate()
  rnd_rotate()
#end


background { color rgb <0, 0.2, 1> * 0.3 }


sky_sphere {
  pigment {
    granite
    perturb()
    scale 1/2
    color_map {
      [ 0.0 color rgbt 1 ]
      [ 0.9 color rgbt 1 ]
      [ 0.9 color rgbt <1, 1, 1, 0> ]
      [ 1.0 color rgbt <1, 1, 1, 0> ]
    }
  }
}


camera {
  location 0
  direction <0, 0, 1> // zoom factor
  up  <0, 1, 0>
  #if (ntsc = true)
    right <(320 / 200) * (10 / 11), 0, 0>
  #else
    right <(640 / 480), 0, 0>
  #end
  rotate x*12
  rotate y*-18
  translate <2, 4, -10>
}


#macro do_box(c1, c2) // same parameter format as for a box object
  // back wall
  triangle { c1, <c2.x, c1.y, c1.z>, <c2.x, c2.y, c1.z> }
  triangle { c1, <c2.x, c2.y, c1.z>, <c1.x, c2.y, c1.z> }
  // left wall
  triangle { c1, <c1.x, c1.y, c2.z>, <c1.x, c2.y, c2.z> }
  triangle { c1, <c1.x, c2.y, c2.z>, <c1.x, c2.y, c1.z> }
  // right wall
  triangle { <c2.x, c1.y, c2.z>, <c2.x, c1.y, c1.z>, c2 }
  triangle { <c2.x, c1.y, c1.z>, c2, <c2.x, c2.y, c1.z> }
  // bottom
  triangle { <c1.x, c2.y, c2.z>, <c1.x, c2.y, c1.z>, <c2.x, c2.y, c1.z> }
  triangle { <c1.x, c2.y, c2.z>, <c2.x, c2.y, c1.z>, c2 }
  // top
  triangle { <c1.x, c1.y, c2.z>, c1, <c2.x, c1.y, c1.z> }
  triangle { <c1.x, c1.y, c2.z>, <c2.x, c1.y, c1.z>, <c2.x, c1.y, c2.z> }
  // front
  triangle { <c1.x, c1.y, c2.z>, <c2.x, c1.y, c2.z>, c2 }
  triangle { <c1.x, c1.y, c2.z>, c2, <c1.x, c2.y, c2.z> }
#end


#declare csize = 48;


/* place csize x csize boxes */
/* first make a random csize x csize "tile" of boxes as one mesh */
#render "\n"
#declare tile1 = mesh {
  #declare xx = 0;
  #while (xx < csize)
    #render concat(str(xx, 0, 0), " of ", str(csize, 0, 0), "\n")
    #declare zz = 0;
    #while (zz < csize)
      #local boxheight = rand(rseed);
      do_box( <xx, 0, zz>, <xx + 1, boxheight * boxheight, zz + 1> )
      #declare zz = zz + 1;
    #end
    #declare xx = xx + 1;
  #end
}


#render "\nMesh built - now placing copies of it\n"


/* now place randomly rotated copies of the mesh */
#declare hcsize = csize / -2;
#declare msize = 15;
union {
  #declare xx = 1 - msize;
  #while (xx < msize)
    #declare zz = 1 - msize;
    #while (zz < msize)
      #declare zz = zz + 1;
      object {
        tile1
        translate <hcsize, 0, hcsize>
        rotate y*90*int(4 * rand(rseed))
        translate <xx * csize, 0, zz * csize>
      }
    #end
    #declare xx = xx + 1;
  #end
  pigment {
    color rgb 1
  }
  finish { ambient 0.5 diffuse 0.5 }
}


light_source {
  <-1000.0, 1200.0, -900.0>
  color red 0.6 green 0.5 blue 0.4
}
light_source {
  <1060.0, 1100.0, -700.0>
  color red 0.4 green 0.5 blue 0.6
}


//end of this file


Post a reply to this message

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