Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Tuesday, 4 December 2012

Fish-eye shader revisited with ruby-processing and processing-2.0

Previously one of the most popular posts (700+ hits) on this blog was my glgraphics post with the fish eye shader. Andres has now incorporated some the shader stuff into processing-2.0, here is essentially the same sketch running in ruby-processing, built with processing-2.0 (which includes built in support for glsl shaders).
##
# Fish Eye
# 
# This fish-eye shader is useful for dome projection.
##

attr_reader :fisheye, :canvas, :use_fish_eye

def setup()
  size(640, 640, P3D)
  @canvas = create_graphics(width, height, P3D)
  @fisheye = load_shader("FishEye.glsl")
  @use_fish_eye = true
  fisheye.set("aperture", 180.0)
end

def draw()
  canvas.begin_draw()
  canvas.background(0)
  canvas.stroke(255, 0, 0)
  (0...width).step(10){ |i| canvas.line(i, 0, i, height)}
  (0...height).step(10){ |i| canvas.line(0, i, width, i)}
  canvas.lights()
  canvas.no_stroke()
  canvas.translate(mouse_x, mouse_y, 100)
  canvas.rotate_x(frameCount * 0.01)
  canvas.rotate_y(frameCount * 0.01)
  canvas.box(100)
  canvas.end_draw()
  shader(fisheye) unless !use_fish_eye
  image(canvas, 0, 0, width, height)
end

def mouse_pressed()
  if (use_fish_eye)
    @use_fish_eye = false
    resetShader()
  else
    @use_fish_eye = true
  end
end

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2