ruby-processingでProcessing->Examples->3D->Lightsの写経

 写経してみたw;

case :Spot
when :Directional
  def setup
    size 640,360,P3D
    fill 204
  end

  def draw
    background 0
    
    no_stroke
    dir_y = map( mouse_y, 0,height, -height/2, height/2)
    dir_x = map( mouse_x, 0,width,  -width/2,  width/2 )
    
    #directional_light( r,g,b, (directioal_light_vector))
    #directional_light( r,g,b, x,y,z)
    directional_light 204,204,204, dir_x, dir_y, -1
    
    translate width/2, height/2, 0
    sphere 80
    translate 200,0,0
    sphere 80
  end
when :Lights1
  def setup
    size 640,360,P3D
    no_stroke
    @spin = 0.0
  end

  def draw
    background 51
    lights
    
    @spin += 0.01
    
    push_matrix
    translate width/2, height/2, 0
    rotate_x PI/9
    rotate_y PI/9 + @spin
    box 150
    pop_matrix
  end
when :Lights2
  def setup
    size 640,360,P3D
    no_stroke
  end

  def draw
    background 0
    translate width/2,height/2,0
    
    point_light(150,100,0,
                200,-150,0)
    directional_light(0,102,255,
                      1,0,0)
    spot_light(255,255,109,
               0,40,200,
               0,-0.5,-0.5,
               PI/2,2)
    
    rotate_y map(mouse_x, 0,width, 0, PI)
    rotate_x map(mouse_y, 0,height,0, PI)
    box 150
    
  end
when :Reflection
  def setup
    size 640,360,P3D
    no_stroke
    color_mode RGB, 1
    fill 0.4
  end
  
  def draw
    background 0
    translate width/2, height/2, 0
    
    light_specular 1,1,1
    
    directional_light 0.8,0.8,0.8,
                      0,0,-1
    
    s = mouse_x/mouse_y.to_f
    specular s,s,s
    sphere 120
  end
when :Spot
  def setup
    size 640,360,P3D
    no_stroke
    fill 204
    
    sphere_detail 60
  end
  def draw
    background 0
    
    directional_light 51,102,126, 0,-1,0
    
    spot_light 204,153,0,
    360,mouse_x,600,
    0,0,-1,
    PI/2,mouse_y
    
    translate width/2,height/2,0
    sphere 120
  end
end