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

Monday 9 September 2013

New Improved Planetarium Basic Sketch

That is more like it decent controls, no need for that reflection nonsense. Another example using Andrés Colubri's planetarium library.
# 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). 
# New improved version using control panel no need for reflection "nastiness"

load_libraries :planetarium, :control_panel
include_package 'codeanticode.planetarium'

attr_reader :cube_x, :cube_y, :cube_z, :panel, :hide

def setup
  # For the time being, only use square windows  
  size(600, 600, Dome::RENDERER)
  @hide = false
  control_panel do |c|
    c.title = "Control"
    c.look_feel "Metal"
    c.slider    :cube_x,  -width / 2.0 .. width / 2.0, 10.0
    c.slider    :cube_y,  -height / 2.0 .. height / 2.0, 10.0
    c.slider    :cube_z,  -width / 2.0 .. 0, -20.0
    @panel = c
  end
end

def mouse_pressed
  @hide = false if hide  # use mouse click to restore control panel
end

# Called five times per frame.
def draw
  unless hide
    @hide = true
    panel.set_visible(hide)
  end
  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

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