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

Sunday, 8 September 2013

Getting ready for jruby-1.7.5

Charlie has called for a big push on jruby-1.7.5 this weekend, I've tested current beta release with ruby-processing, and as far as I can I tell it will be good to go. I'm wondering whether there might be something else I could do to boost up the next release? Currently I'm thinking of dropping the perlin noise gem example which seems a bit iffy now. Perhaps another gem to replace it? I've been messing with Andres Colubri planetarium library (but will probably give it miss) can't get java reflection to work in reverse with "pre()".
But then I had brainwave!!!
# The planetarium library is designed to create real-time projections on 
# spherical domes. It is based on the FullDome project by Christopher 
# Warnow (ch.warnow@gmx.de):
# https://github.com/mphasize/FullDome
#
# A brief descrition on how it works: a 360° view of the scene is generated
# by rendering the scene 6 times from each direction: positive x, negative x, 
# positive y, and so on. The output of each rendering is stored inside a cube map 
# texture, which is then applied on a sphere representing the dome.
# Hence, the library calls the draw method 6 times per frame in order to update  
# the corresponding side of the cube map texture (in reality, only 5 times since  
# the bottom side of the cube map is not invisible on the dome). 
# I can't get 'pre' to work correctly on ruby processing (reflection in reverse)
# so here we use mouse_released instead

load_library :planetarium
include_package 'codeanticode.planetarium'

attr_reader :cube_x, :cube_y, :cube_z

def setup
  # For the time being, only use square windows  
  size(600, 600, Dome::RENDERER)
  @cube_x, @cube_y, @cube_z = width/2, height/2, -width/4
end

# Called one time per frame when pre, or to order via mouse.
def mouse_released
  # The dome projection is centered at (0, 0), so the mouse coordinates
  # need to be offset by (width/2, height/2)
  @cube_x += ((mouse_x - width * 0.5) - cube_x) * 0.2
  @cube_y += ((mouse_y - height * 0.5) - cube_y) * 0.2
end

# Called five times per frame.
def draw
  background(0)

  push_matrix
  translate(width/2, height/2, 300)

  lights

  stroke(0)
  fill(150)
  push_matrix
  translate(cube_x, cube_y, cube_z)
  box(50)
  pop_matrix

  stroke(255)
  lines_amount = 10
  (0 ... lines_amount).each do |i|
    ratio = i/(lines_amount - 1.0)
    line(0, 0, cos(ratio * TWO_PI) * 50, sin(ratio * TWO_PI) * 50)
  end
  pop_matrix
end

def key_pressed
  if (key == CODED)
    @cube_z -= 5 if (key_code == UP)
    @cube_z += 5 if (key_code == DOWN)
  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