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

Tuesday, 24 June 2014

Decoupling Sub Classes Using Hook Messages (in ruby-processing)

About time I posted a bit more code:-
# An example demonstrating the use of a hook to decouple subclasses in 
# ruby-processing. The base class here is Spin, and we have included 
# post_initialize as the hook (it does nothing in the base class). SpinArm
# and SpinSpots both subclass Spin, but only SpinSpots requires the hook to
# change the initialization. Note the use the hook means the subclass does 
# not need to call super

def setup
  size 640, 360
  @arm = SpinArm.new({ x: width/2, y: height/2, s: 0.01 })
  @spots = SpinSpots.new({ x: width/2, y: height/2, s: -0.02, d: 90.0 })
end

def draw
  background 204
  @arm.display
  @spots.display
end


class Spin

  attr_accessor :x, :y, :speed
  attr_accessor :angle

  def initialize(args = {})
    @x, @y = args[:x], args[:y]
    @speed = args[:s]
    @angle = args[:angle] || 0.0
    post_initialize(args)  # this is the hook
  end

  def update
    @angle += speed
  end

  def post_initialize args
    nil
  end

end


class SpinArm < Spin # inherit from (or "extend") class Spin
  # NB: initialize inherited from Spin class

  def display
    stroke_weight 1
    stroke 0
    push_matrix
    translate x, y
    update
    rotate angle
    line 0, 0, 165, 0
    pop_matrix
  end
end


class SpinSpots < Spin
  attr_accessor :dim

  def post_initialize args
    @dim = args[:d]
  end

  def display
    no_stroke
    push_matrix
    translate x, y
    update
    rotate angle
    ellipse(-dim/2, 0, dim, dim)
    ellipse(dim/2, 0, dim, dim)
    pop_matrix
  end
end

Ruby 2D games using ruby-processing

Morohoshi-san is developing a ruby games application based on dxruby_sdl here is the tweet from ruby-gems:-




This is a sketch from dxruby_sdl on github run on my linux box (better if I had game controllers I am sure).

Here is the project on github.

Wednesday, 18 June 2014

JRubyArt is now using java extensions to generate ruby (Vecmath, ArcBall, DegLut)

Still waiting for @headius to confirm I am the right track with my java extensions to jruby. But I am not waiting forever so now my updated JRubyArt now includes these extensions:-
  1. A vecmath library, featuring Vec2D and Vec3D classes (written in java, but loaded as ruby)
  2. Also featured in the vecmath library is an ArcBall class  (also written in java, but loaded as ruby)
  3. A deglut library which is  now all, java uses a sin90 look up table to create sin cos functionality(is actually slightly faster than regular math sin/cos)
The extension stuff is written up here 

Thing to do:-
  1. Fix overloaded methods for color? eg background, fill, stroke
  2. Experiment with jafama (again, why is Jonathan Feinberg including google guava libs)
  3. improve build now at least a two stage process
  4. Clone and BFG clobber processing-2.2.1 snapshot?
  5. Create a renderer class that is initialized with PApplet, and has medods to send vertex(arg), normal(arg), curvedVertex(arg) etc. where arg is an instance of Vec3D?

Friday, 6 June 2014

Grapher sketch in ide

OOPs this is what sketch should look like, I forgot I had modified sketch to run with my degree look up tables for cosine and sine see highlighted line in editor. See also blue rubies for header

Thursday, 5 June 2014

Running the spec_test.rb in the processing ide

This is what happens when I run the specs_test sketch from processing ide:-
def setup
  size(100, 100, P3D)
  puts(Java::Processing::opengl::PGraphicsOpenGL.OPENGL_VENDOR)
  puts(Java::Processing::opengl::PGraphicsOpenGL.OPENGL_RENDERER)
  puts(Java::Processing::opengl::PGraphicsOpenGL.OPENGL_VERSION)
  puts(Java::Processing::opengl::PGraphicsOpenGL.GLSL_VERSION)
  puts(Java::Processing::opengl::PGraphicsOpenGL.OPENGL_EXTENSIONS)
end

Initially nothing seems to happen, but output to console happens on closure of the sketch (this is a temporary feature according to Fukuda-san)

Wednesday, 4 June 2014

Fukuda-san has made some progress towards a ruby mode for processing

NB: Post updated 5 July 2014, so the first two comments below refer to a non-working linux and windows version.
Working, on linux (for me) and windows (Fukuda-san) as well as original Mac version (for which Makefile is written) see below for ruby in ide on my linux box

The sketch is saved to /tmp on linux as an *.rb file prior to running (similar to processing). To get the ide to look right you need a theme, here I stole fjenetts coffee-script theme, blue diamonds would look nice for ruby. You can get the Fukuda-san repo here. For a modified Makefile for linux (not archlinux) see this gist. Possibly it may tempt some processing users (especially Windows users) to dabble with ruby, but I have never been very happy with the editor in the processing ide (and there are other limitations) neverthless kudos to Fukuda-san. I expect to report more experiments soon.

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