// key material

global_settings { assumed_gamma 1.9 }

#include "colors.inc"
#include "textures.inc"

camera {
  location <-.01, .7, -20>
  direction <0, 0, 3>
  look_at 0
}

light_source { <200, 150, -100> color White }
light_source { <-20, 20, -5> color Gray50 }

background { rgb <.08, .1, .3>*0.7 }

#declare KeyPlate = difference {
  cylinder { -.1*z, .1*z, 1 }
  cylinder { -.11*z, -.09*z, .9 }
  cylinder { .11*z, .09*z, .9 }
  cylinder { -.11*z, .11*z, .2 translate <-.35, 0, 0> }
}

#declare KeyNut = union {
  cone { 0*x, 0, .5*x, .05 }
  cylinder { .5*x, 4*x, .05 }
}

#declare KeyBeard = difference {
  box { <0, -.3, -.1>, <3, .3, .1> }
  box { -.5, .5 rotate 45*z translate <3.2, .4, 0> }
  box { -.5, .5 rotate 45*z translate <3, -.4, 0> }
  box { -.5, .5 rotate 45*z scale <1, 1.2, 1> translate <1.8, -.9, 0> }
  box { -.5, .5 rotate 45*z scale <1, .9, 1> translate <.8, -.71, 0> }
  box { -.5, .5 rotate 45*z scale <1, 1, 1> translate <1.3, -.72, 0> }
  box { -.5, .5 rotate 45*z scale <.9, 1, 1> translate <2.1, -.79, 0> }
  //
  object { KeyNut translate <.1, .22, -.07> }
  object { KeyNut translate <.08, .1, -.07> }
  object { KeyNut translate <.2, -.05, -.07> }
  object { KeyNut translate <.6, -.2, -.07> }
  //
  object { KeyNut translate <.1, .22, .07> }
  object { KeyNut translate <.08, .1, .07> }
  object { KeyNut translate <.2, -.05, .07> }
  object { KeyNut translate <.6, -.2, .07> }
}

// key
#declare Key = union {
  object { KeyPlate }
  text {
    ttf "cyrvetic.ttf", "42", .05, 0
    translate <-.5, -.4, 0>
    scale <.4, .4, 1>
    translate <.2, .2, -.1>
  }
  text {
    ttf "cyrvetic.ttf", "23", .05, 0
    translate <-.5, -.4, 0>
    scale <.4, .4, 1>
    translate <.2, -.2, -.1>
  }
  object { KeyBeard scale <1.3, 1, .7> translate .9*x }
  texture { Chrome_Metal }
  translate -1.5*x
}

// endless ocean
plane {
  y, -.5
  pigment { rgb <.08, .1, .3> }
  finish { reflection .5 }
  normal { ripples .4 translate -.5 scale 6 frequency 20 }
}

// moon
sphere {
  0, 1
  pigment {
    bozo turbulence .7
    color_map {
      [0 color Gray60]
      [.7 color White]
      [1 color White]
    }
  }
  scale 10
  translate <30, 18, 200>
}

// clouds
sphere {
  0, 1 hollow
  no_shadow
  pigment {
    bozo scale <1, 1/6, 1>*.2 turbulence .5
    octaves 3
    lambda 6
    color_map {
      [0 color Gray30 transmit 1]
      [.5 color Gray30 transmit 1]
      [.8 color Gray40 transmit .1]
      [1 color Gray50]
    }
  }
  finish { ambient 1 diffuse 0 }
  scale 150
  rotate 50*y
}

#declare A = seed(357689)

#declare KC = 0
#while (KC < 10)
object {
  Key
  rotate -(rand(A)*70-35)*z
  rotate (rand(A)*180-90)*y
  translate <rand(A)*20-10, -.5, rand(A)*30-15-3>
}
#declare KC = KC+1
#end