 }
 
 let stderr = StandardErrorOutputStream()
+
 struct Vec {
   let x, y, z : Double
   init() { self.init(x:0, y:0, z:0) }

  Sphere(rad:600, p:Vec(x:50,y:681.6-0.27,z:81.6),e:Vec(x:12,y:12,z:12),   c:Vec(),  refl:Refl_t.DIFF) //Lite
]
func clamp(x : Double) -> Double { return x<0 ? 0 : x>1 ? 1 : x; }
func toInt(x : Double) -> Int { return Int(pow(clamp(x),1/2.2)*255+0.5); }
func intersect(r : Ray, inout t: Double, inout id: Int) -> Bool {
  let n = spheres.count
  let inf=1e20
  var t = inf
  for (var i = n-1; i >= 0; i--) {
    let d = spheres[i].intersect(r)
    if (d != 0.0 && d<t){t=d;id=i;}
  }
  return t<inf
}

}

struct Ray { let o, d : Vec; init(o : Vec, d : Vec) {self.o = o; self.d = d}}

enum Refl_t { case DIFF; case SPEC; case REFR }  // material types, used in radiance()

struct Sphere {
  let rad : Double       // radius
  let p, e, c : Vec      // position, emission, color
