//  Bill Durbin - October, 1995
// A simple sand castle being destroyed. A plastic shovel, a beach ball, 
// popsicle sticks, and some cliffs can also be found here

#include "colors.inc"    
#include "shapes.inc"   
#include "textures.inc"

camera {
   location <95, 20, -30>
   look_at   <40, 20, 40> 
}
                                 
fog {color White distance 1550 }  // The almighty Fog for that cool 
                                  // distance effect.

//--------- Creams & Grays Kakhi  // Gratuitously stolen from stones.inc
#declare Grnt11 =
texture {
pigment
 {granite
  turbulence 0.6
  color_map
   {[0.000, 0.154   color rgbf <0.800, 0.651, 0.557, 0.000>
                    color rgbf <0.996, 0.835, 0.737, 0.000>]
    [0.154, 0.308   color rgbf <0.996, 0.835, 0.737, 0.000>
                    color rgbf <0.800, 0.651, 0.557, 0.000>]
    [0.308, 0.444   color rgbf <0.800, 0.651, 0.557, 0.000>
                    color rgbf <0.694, 0.624, 0.604, 0.004>]
    [0.444, 0.615   color rgbf <0.694, 0.624, 0.604, 0.004>
                    color rgbf <0.800, 0.651, 0.557, 0.000>]
    [0.615, 0.812   color rgbf <0.800, 0.651, 0.557, 0.000>
                    color rgbf <0.725, 0.655, 0.651, 0.000>]
    [0.812, 1.001   color rgbf <0.725, 0.655, 0.651, 0.000>
                    color rgbf <0.800, 0.651, 0.557, 0.000>]
   }
 }
 }

//--- Popsicle Stick wood texture... very light.. modification of one of
//     the DMFWood textures in textures.inc.. DMFWood4 I believe

#declare Lightwood = texture {
 pigment {
   bozo
   turbulence 0.04
   color_map {
      [0.000, 0.256   color red  0.604  green  0.510  blue  0.378  filter  0.000
                      color red  0.631  green  0.525  blue  0.390  filter  0.000]
      [0.256, 0.393   color red  0.631  green  0.525  blue  0.390  filter  0.000
                      color red  0.647  green  0.533  blue  0.390  filter  0.000]
      [0.393, 0.581   color red  0.647  green  0.533  blue  0.390  filter  0.000
                      color red  0.604  green  0.510  blue  0.375  filter  0.000]
      [0.581, 0.726   color red  0.604  green  0.510  blue  0.375  filter  0.000
                      color red  0.659  green  0.522  blue  0.402  filter  0.000]
      [0.726, 0.983   color red  0.659  green  0.522  blue  0.402  filter  0.000
                      color red  0.631  green  0.525  blue  0.386  filter  0.000]
      [0.983, 1       color red  0.631  green  0.525  blue  0.386  filter  0.000
                      color red  0.604  green  0.510  blue  0.378  filter  0.000]
   }
   scale <0.3, 0.3, 3>
   translate <10, 0, 0>
 }
 finish {
   ambient 0.5
   diffuse 0.8
 }
}

// My own little creations here.. to add some realism to the popsicle
// sticks, I decided to put some popsicle stains on them.. this decidedly
// makes the popsicle sticks just what they are.. otherwise they might look
// like tongue depressors or something.  three flavors for your pleasure...


#declare Green_Stain = texture {
   pigment {
      gradient <0,-1,0>
      color_map {
         [0.0, 0.55  color red 0.0 green 0.4 blue 0.0 filter 0.75
                    color red 0.0 green 0.4 blue 0.0 filter 0.85] 
         [0.55, 0.75  color red 0.0 green 0.4 blue 0.0 filter 0.85
                    color Clear]
         [0.75, 1    color Clear
                    color Clear]
         }
   }
}
#declare Purple_Stain = texture {
   pigment {
      gradient <0,-1,0>
      color_map {
         [0.0, 0.5  color red 0.4 green 0.0 blue 0.5 filter 0.75
                    color red 0.4 green 0.0 blue 0.5 filter 0.85] 
         [0.5, 0.7  color red 0.4 green 0.0 blue 0.5 filter 0.85
                    color Clear]
         [0.7, 1    color Clear
                    color Clear]
         }
   }
}

#declare Red_Stain = texture {
   pigment {
      gradient <0,-1,0>
      color_map {
         [0.0, 0.6  color red 0.4 green 0.0 blue 0.0 filter 0.75
                    color red 0.4 green 0.0 blue 0.0 filter 0.85] 
         [0.6, 0.8  color red 0.4 green 0.0 blue 0.0 filter 0.85
                    color Clear]
         [0.8, 1    color Clear
                    color Clear]
         }
   }
}

// And here's the popsicle sticks minus the stain.. that comes later

#declare Popsicle_Stick = object {
        union{
                box {<0,-8,0>,<1,0,0.2>}
                cylinder {<0.5,0,0>,<0.5,0,0.2>,0.5}
                cylinder {<0.5,-8,0>,<0.5,-8,0.2>,0.5}
        }
        texture {Lightwood
                 rotate <-90,0,0>}
}

// An all-purpose CSG Beach Ball

#declare Beach_Ball = object {
  union{  
    difference {    
        intersection {        
                sphere {<2,2,-2>,2}
                box {<0,0,-4>,<2,2,0>}
           texture {pigment {Blue}
                 finish {Glossy}}
        }
        cylinder{<2,2,-4>,<2,2,0>,0.5}
    }    
    difference {
        intersection {        
                sphere {<2,2,-2>,2}
                box {<2,2,-4>,<4,4,0>}
           texture {pigment {Green}
                    finish {Glossy}}
        }
        cylinder{<2,2,-4>,<2,2,0>,0.5}
     }    
     difference {   
        intersection {        
                sphere {<2,2,-2>,2}
                box {<2,0,-4>,<4,2,0>}
           texture {pigment {Red}
                    finish {Glossy}}
        }
        cylinder{<2,2,-4>,<2,2,0>,0.5}
     }
     difference {
        intersection {        
                sphere {<2,2,-2>,2}
                box {<0,2,-4>,<2,4,0>}
           texture {pigment {Yellow}
                    finish {Glossy}}
        }
        cylinder{<2,2,-4>,<2,2,0>,0.5}
     }   
     intersection {        
        sphere {<2,2,-2>,2}
        cylinder{<2,2,-4>,<2,2,0>,0.5}
        texture {pigment {White}
                 finish {Glossy}}
     }
  }
}

// The handle to the little kiddies' shovel. Separate from the scoop in the
// hopes of maybe making a rake also if there was room... there isnt much 
// left though.

#declare Handle = object {
    union {
        difference {
            torus {0.75,0.25
                   rotate<90,0,0>
                   translate <1,1,0>}
            box {<0,0,-1>,<2,1,1>}
        }
        difference {
            cylinder {<0.25,0,0>,<0.25,1.01,0>,0.25}
            box {<0,-1,-1>,<1,0,1>
                 rotate<0,0,45>}
        }
        difference {
            cylinder {<1.75,0,0>,<1.75,1.01,0>,0.25}
            box {<0,-1,-1>,<1,0,1>
                 rotate<0,0,45>
                 translate<0.585,0,0>}
        }
        difference {
        difference {
            cylinder {<0,0.25,0>,<2,0.25,0>,0.25}
            box {<0,-1,-1>,<1,0,1>
                 rotate<0,0,-225>}
        }  
            box {<0,-1,-1>,<1,0,1>
                 rotate<0,0,-225>
                 translate<2,0,0>}
        }
        difference {
            cylinder {<1,1.75,0>,<1,4.5,0>,0.25}
            cylinder {<0.5,4.5,-0.25>,<1.5,4.5,-0.25>,0.5}
        }
    }
}

// Scoop of the shovel. 

#declare Scoop = object {
    merge {        
        union {
            box {<0.5,1,-0.5>,<2.5,3.5,-0.375>}
            box {<1,0.5,-0.5>,<2,1.01,-0.375>}
            cylinder {<1,1,-0.5>,<1,1,-0.375>,0.5 }
            cylinder {<2,1,-0.5>,<2,1,-0.375>,0.5 }
        }
        difference {    
          difference {
          difference {
            cylinder {<0.5,1,0>,<0.5,3.5,0>,0.5 }
            cylinder {<0.5,0.9,0>,<0.5,3.6,0>,0.375 open}
          }
            box {<0,0.9,0>,<1,3.6,0.6>}
          }
            box {<0.5,0.9,-0.5>,<1,3.6,0.6>}
        }
        difference {    
          difference {
          difference {
            cylinder {<2.5,1,0>,<2.5,3.5,0>,0.5 }
            cylinder {<2.5,0.9,0>,<2.5,3.6,0>,0.375 open}
          }
            box {<2,0.9,0>,<3,3.6,0.6>}
          }
            box {<2,0.9,-0.5>,<2.5,3.6,0.6>}
        }
        difference {    
          difference {
          difference {
            cylinder {<1,0.5,0>,<2,0.5,0>,0.5 }
            cylinder {<0.9,0.5,0>,<2.1,0.5,0>,0.375 open}
          }
            box {<0.9,0.5,-0.5>,<2.1,1,0.6>}
          }
            box {<0.9,0,0>,<2.1,1,0.6>}
        }
        difference {
          difference {
          difference {
          difference {
          difference {
            torus { 0.5,0.5
                   rotate <90,0,0>}
            torus { 0.5,0.375
                   rotate <90,0,0>}
          }  
            box {<-1,0,-0.5>,<1,1,0.5>}
          }
            box {<0,-1,-0.5>,<1,1,0.5>}
          }
            box {<-1,-1,0>,<1,1,0.6>}
          }  
            cylinder {<0,0,-0.5>,<0,0,0.5>,0.5}
          rotate <0,0,90>
          translate <2,1,0>
        }
        difference {
          difference {
          difference {
          difference {
          difference {
            torus { 0.5,0.5
                   rotate <90,0,0>}
            torus { 0.5,0.375
                   rotate <90,0,0>}
          }  
            box {<-1,0,-0.5>,<1,1,0.5>}
          }
            box {<0,-1,-0.5>,<1,1,0.5>}
          }
            box {<-1,-1,0>,<1,1,0.6>}
          }  
            cylinder {<0,0,-0.5>,<0,0,0.5>,0.5}
          translate <1,1,0>
        }
    }
}

// Gluing the handle and the scoop together to make a shovel.

#declare Shovel = object {
    merge {
        object {Scoop
                rotate <0,180,0>
                translate <3,4,0>
        }
        object {Handle
                translate <0.5,0,0.25>
        }
        translate <-1.5,-3.25,-0.25>
    }
}

// Here's the sky.. I love the sky that Eric Jorgensen used in his example
// file in Terrain Maker.. this is basically the same thing, only i put
// a different sky texture on the sphere.  * Also gratuitously ripped from
// the example.pov file included in Terrain Maker

#declare DaSky = sphere { 
  <0,0,0>,0.98
  texture {
    Blue_Sky2
    finish {reflection 0.0 diffuse 0.0 ambient 1.0}
  }  
}
             
difference {
     sphere { <0,0,0>,1}
     object {DaSky}

     scale <3000,500,3000>
     texture {
          Blue_Sky2
          finish {reflection 0.0 diffuse 0.0 ambient 1.0} 
     }  
     no_shadow
}

// This was also inspired by Eric Jorgensen's water.. no bumps however..
// I wanted a relatively (ok, completely) calm moat and it looks good in 
// the background 'ocean' as well.

plane {   
     <0,1,0>, 0.5
     texture {
       pigment {color rgb<0.0,0.1,0.2>}
       finish {phong 1 reflection .5 ambient 0.1 diffuse 0.2}
     }

}

// The Sand Castle.  I used Terrain Maker for the height field and
// plugged it into here.

height_field {
     gif "castl.ghf"
     scale <100,30,100>
     texture {Grnt11
     finish {crand 0.05 diffuse 0.7 ambient 0.2}
     }
     smooth                        
}

// The sand around the sand castle...  gap between the two is the moat

height_field {
     gif "sand.ghf"
     scale <420,37,400>
     translate <-225,0,-60>
     texture {Grnt11
     finish {crand 0.05 diffuse 0.7 ambient 0.2}
     }
     smooth                     
}

// Some wonderful cliffs in the background, again, Terrain Maker

height_field {
     gif "cliffs.ghf"
     scale <800,100,800>
     texture {
       pigment { 
         image_map {
           gif "cliffs.ghf"
         }
         scale <800,100,800>
       }
     finish {diffuse 0.7 ambient 0.2}
     }
     translate <-400,0,100>
     smooth                        
}

// Here's three popsicle sticks complete with stains..  They used to be
// the bridge to this fine Castle, but now one is floating in the moat.

object {Popsicle_Stick
        texture {Red_Stain
                 scale <1,-9,1>
                 translate<0,0.5,0>}
        scale <2,2,2>
        rotate <-90,0,0>
        translate <43,1.8,-1.5>
}

object {Popsicle_Stick
        texture {Green_Stain
                 scale <1,-9,1>
                 translate<0,0.5,0>}
        scale <2,2,2>
        rotate <-90,10,0>
        translate <46,1.8,-1.5>
}
object {Popsicle_Stick
        texture {Purple_Stain
                 scale <1,-9,1>
                 translate<0,0.5,0>}
        scale <2,2,2>
        rotate <-90,45,0>
        translate <52,0.5,6>
}

// Beach balls belong on the beach.  That's where I stuck this one.

object {Beach_Ball
        translate <-2,-2,2>
        scale <7,7,7>
        rotate <30,-30,0>
        translate <70,14,120>
        }

// And our construction tool is here too. Purely for effects, mind you. A 
// REAL little kid would NEVER leave his toys at the beach.  Yeah right.

object {Shovel
        texture {pigment {NeonPink}
                 finish {Glossy}}
        translate <-1.5,0,0>
        //bounded_by {box{<-2.5,-0.1,-0.8>,<2.5,8,0.8>}}
        scale <3,3,3>
        rotate <140,100,0>
        translate <20,6,-5>
}

// Orange light for that 'sunsetty' feeling

light_source { <-1500, 3000, -5000> color Orange}

