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

Thursday, 17 December 2009

Using the Anar+ library in ruby-processing

First you need to put both opengl and anar libraries in eponymous folders (same name) and them both in an outer folder library, then your sketch can load the libraries 'easy-peasy'. If you are not on linux, you do not need not run full screen but you should because its great. This sketch apart from the full_screen is virtually a straight translation of a java processing example from http://anar.ch. NB Use scroll wheel to zoom or equivalent gizmo.


load_libraries 'anar', 'opengl'
import "anar" if library_loaded? "anar"
import "processing.opengl" if library_loaded? "opengl"

attr_accessor :my_obj
full_screen

def setup()
  library_loaded?(:opengl) ? setup_opengl : fail_opengl
  frame_rate(200)

  Anar.init(self)
  Anar.draw_axis(true)

  init_form()
end

def setup_opengl
  render_mode OPENGL
  hint ENABLE_OPENGL_4X_SMOOTH #optional
end

def init_form()

  #Create a new Line
  pts = Pts.new

  pts.add(Anar.Pt(100,110,20))
  pts.add(Anar.Pt(110,100,40))
  pts.add(Anar.Pt(110,90,60))
  pts.add(Anar.Pt(90,90,90))
  #Create a Face
  f = Star.new(50,100,5)
  #Extrude the face along the Line
  @my_obj = Extrude.new(f,pts)
  Anar.cam_target(my_obj)
  Anar.sliders(my_obj)
end

def draw()
  background(155)
  my_obj.draw()
end

def fail_opengl
  abort "!!!You absolutely need opengl for this sketch!!!"
end

#Toggle the display of the sliders
def keyPressed()
  Anar.sliders_toggle()
end

























Original author Guillaume LaBelle (I think?), sliders are bit tiny and fall off the end but functionality is superb (there might have been sound as there is some complaint about lack of promidi, however nothing happened for me when I loaded the appropriate libraries).

1 comment:

  1. Yes, ProMidi is optional, it's only used to control the sliders through Midi (when both library and a midi input is found). The sliders are very basic, they meant to be redefined by the user, we(*) thought it may be useful to provide predefined sliders lists. This is the same for the camera, it's very elementary. You could turn this off by using (in setup()):
    Anar.defaultScene= false;
    Then, you could use your favorite camera.

    I'm glad to see your example, and your work as well.

    (*) We is me and Julien Nembrini

    ReplyDelete

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