# 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
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:-
Labels:
hook messages,
inheritance,
ruby-processing,
Sandi Metz
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.
dxruby_rp5 (0.0.4): `dxruby-rp5` is a ruby library for 2D graphics and game. `dxruby-rp5` uses `ruby-processing` and… http://t.co/Sr2i0zHnsv
— RubyGems (@rubygems) June 24, 2014
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.
Labels:
2D games,
ruby,
ruby-processing
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:-
Thing to do:-
- A vecmath library, featuring Vec2D and Vec3D classes (written in java, but loaded as ruby)
- Also featured in the vecmath library is an ArcBall class (also written in java, but loaded as ruby)
- 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)
Thing to do:-
- Fix overloaded methods for color? eg background, fill, stroke
- Experiment with jafama (again, why is Jonathan Feinberg including google guava libs)
- improve build now at least a two stage process
- Clone and BFG clobber processing-2.2.1 snapshot?
- 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?
Labels:
jruby extension,
JRubyArt,
ruby-processing
Thursday, 12 June 2014
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
Labels:
blue rubies,
mode theme
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) endInitially nothing seems to happen, but output to console happens on closure of the sketch (this is a temporary feature according to Fukuda-san)
Labels:
console output,
processing ruby mode
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.
Ruby mode for Processing ちょっと動いたー pic.twitter.com/x3ltoiIL8U
— tyfkda (@tyfkda) June 2, 2014
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.
Labels:
processing ide,
ruby mode
Subscribe to:
Posts (Atom)
Followers
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2