// Weird space ball
// )C( 5/1994 Christian Perle

#include "colors.inc"

camera {
  location <0, 5, -15>
  direction <0, 0, 1.5>
  up <0, 1, 0>
  right <4/3, 0, 0>
  look_at <0, 0.1, 0>
}

light_source { <9, 12, 0> color White }

light_source { <-6, 15, -6> color White }

light_source { <4, 7, 10> color Gray85 }

light_source { <-3, -10, -8> color Gray80 }

#declare Dist = .8     // Pole distance
#declare Alt  = .6     // Pole altitude

#declare Pole = union {
  sphere {
    <Dist, Alt, Dist>, .1
  }
  cylinder {
    <Dist, 0, Dist>, <Dist, Alt-.05, Dist>, .04
  }
  pigment { color Magenta }
  finish { phong 1 }
}

// Ball thing with belt and poles
#declare SBall = union {
  intersection {
    sphere { <0, 0, 0>, 1 }
    plane { y, 0 inverse }
    pigment { color blue .1 }
    finish { phong 1 reflection .2 }
  }
  cylinder {
    <0, 0, 0>, <0, .2, 0>, 1.1
    pigment {
      gradient y
      scale .1
      translate y*0.075
      turbulence .3
      color_map {
        [0.0 color Gray60]
        [0.5 color Orange]
        [1.0 color Gray60]
      }
      quick_color Orange
    }
  }
  object { Pole }
  object { Pole rotate 90*y }
  object { Pole rotate -90*y }
  object { Pole rotate 180*y }
  bounded_by { cylinder { <0, -.02, 0>, <0, 1.02, 0>, 1.414*Dist+0.12 } }
}

#declare Sidering = difference {
  torus { 4, .15 }
  sphere { <0, 0, 0>, 4 }
  pigment { Gray65 }
  finish { phong 1 phong_size 10 }
}

#declare Tube = intersection {
  union {
    sphere { <0, 0, -2.2>, .25 }
    cylinder { <0, 0, -2.2>, <0, 0, 2.2>, .25 }
    sphere { <0, 0, 2.2>, .25 }
  }
  plane { y, 0 inverse }
  pigment { color blue .1 }
  finish { phong 1 reflection .2 }
}

#declare Tyre = difference {
  cylinder { <0, 0, 0>, <1, 0, 0>, 1.4 }
  cone {
    <.5, 0, 0>, 1
    <1.1, 0, 0>, 1.3
  }
}

#declare Car = union {
  difference {  // Car body
    box { <-1, 0, -2>, <1, 1, 2> }
    cylinder { <-1.1, 5.2, -1.5>, <1.1, 5.2, -1.5>, 5 }
    pigment {
      bozo
      scale <.25, .25, .5>
      color_map {
        [0 color Green]
        [1 color red .7 green .5 blue .3]
      }
      quick_color Green
    }
  }
  union {  // Tyres
    object { Tyre scale .4 translate <1, 0, -.9> }
    object { Tyre scale .4 translate <1, 0, .9> }
    object { Tyre scale .4 rotate 180*y translate <-1, 0, -.9> }
    object { Tyre scale .4 rotate 180*y translate <-1, 0, .9> }
    pigment { Gray30 }
    finish { phong 1 phong_size 10 }
  }
  sphere {  // Windshield
    <0, 0, 0>, 1
    scale <.8, .2, 1.2>
    rotate -20*x
    translate 0.5*y
    pigment { color blue .1 }
    finish { phong 1 reflection .2 }
  }
  union {  // Lights
    box { <-.95, .05, -2.05>, <-.65, .15, -2> }
    box { <.65, .05, -2.05>, <.95, .15, -2> }
    pigment { Yellow }
    finish { ambient .5 }
  }
  union {
    box { <-.95, .2, 2>, <-.8, .8, 2.05> }
    box { <.8, .2, 2>, <.95, .8, 2.05> }
    pigment { Red }
    finish { ambient .5 }
  }
  bounded_by { box { <-1.42, -.58, -2.07>, <1.42, 1.02, 2.07> } }
}

#declare SpaceBall = union {
  object { SBall }
  object { Tube translate 2*x }
  object { Tube translate -2*x }
  intersection {
    sphere { <0, 0, 0>, 4 }
    plane {
      y, 0
      inverse
    }
    pigment { color Gray95 filter .9 }
    finish { phong .7 }
    translate y*0.05
  }
  intersection {
    sphere {
      <0, 0, 0>, 4
      pigment { Orange }
    }
    plane {
      y, 0
      pigment {
        bozo
        scale .2
        color_map {
          [0 color Blue]
          [.5 color Black]
          [1 color Blue]
        }
        quick_color Blue
      }
      finish { ambient .3 }
    }
  }
  object { Sidering }
  object {
    Car
    scale .2
    rotate 40*y
    translate <2.8, .112, -.5>
  }
  object {
    Car
    scale .2
    rotate -80*y
    translate <-.3, .112, -2.6>
  }
  bounded_by { sphere { <0, 0, 0>, 4.17 } }
}

#declare Planetoid = sphere {
  <0, 0, 0>, .5
  pigment {
    bozo
    scale <.25, .1, .25>
      color_map {
        [0 color Blue]
        [0.4 color Blue]
        [0.6 color Green]
        [0.7 color red .9 green .7 blue .5]
        [0.9 color red 1 green .8 blue .6]
        [1.0 color White]
      }
    quick_color Blue
  }
}

object {
  SpaceBall
  rotate y*20
}

object {
  Planetoid
  rotate 80*y
  translate <-4, 3, 4>
}

object {
  Planetoid
  translate <4, 4, 2>
}

sphere {  // Sky sphere
  <0, 0, 0>, 1000
  pigment {
    gradient y
    color_map {
      [0.0 color blue .2]
      [0.4 color red .2 blue .2]
      [0.47 color red .3 blue .3]
      [0.53 color red .3 blue .3]
      [0.6 color red .2 blue .2]
      [1.0 color blue .2]
    }
    scale 1000
    translate 300*y
    quick_color red .2 blue .2
  }
  finish { ambient 1 diffuse 0 }
}