Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Wednesday, 18 February 2009

ruby-processing (I had to try it out)

Hate parentheses, then you'll love ruby (there are several ways to access processing libraries from ruby, perhaps the simplest is to install the ruby-processing gem) here's an example I've posted as applet on my web-site. A simple saucer animation that uses two images, but you have to be patient Viewing an applet entails loading the JRuby runtime, an ~ 9 MB .jar which can take a while to download. as well the processing core library, some implementation wrinkles to be ironed out there then.....
Views OK for me using IE8 and chrome on Windows, and Firefox...
Note change from camel case to more 'C' like syntax, preferred in ruby (either work)
The alternative vim syntax highlighted ruby code here, really shows why you don't need parentheses.

   1:=begin
2: animated_image.rb author Martin Prout
3: loads two images one as background one as animated object
4:=end
5:
6:require 'ruby-processing'
7:
8:class StarfieldImageSketch < Processing::App
9: attr_accessor :loc, :vel, :acc # get and set
10: attr_reader :saucer, :starfield # get only
11:
12: def setup
13: @loc = PVector.new 20.0, 20.0
14: @vel = PVector.new
15: @acc = PVector.new 0.01, 0.01
16: @saucer = load_image "saucer.gif"
17: @starfield = load_image "space.jpg"
18:
19: end
20:
21: def draw
22: background starfield
23: image saucer, loc.x, loc.y
24: update
25: boundary
26: end
27:
28: def boundary
29: if loc.x > width - saucer.width
30: loc.x = width - saucer.width
31: vel.x = 0.0
32: acc.x = -0.01
33: end
34: if loc.y > height - saucer.height
35: loc.y = height - saucer.height
36: vel.y = 0.0
37: acc.y = -0.01
38: end
39: if loc.x < 0
40: loc.x = 0.0
41: vel.x = 0.0
42: acc.x = 0.01
43: end
44: if loc.y < 0
45: loc.y = 0.0
46: vel.y = 0.0
47: acc.y = 0.01
48: end
49: end
50:
51: def update
52: vel.add acc.get
53: loc.add vel.get
54: end
55:end
56:
57:
58:StarfieldImageSketch.new :title => "Starfield Image Animation", :width => 800, :height => 500


Revised 24 Feb 2009 to produce a more interesting applet, if you had to wait for it, the previous applet was probably a bit disappointing. Now revised to use version 1.08, strange how ruby is now blue!!!

There's an interesting little discussion between Shiffman (processing) and Jashkenas (ruby-processing) on the processing discourse board, we don't seem to be getting a lot of that sort of thing on our blogs..........

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=implementations;action=display;num=1228315955


Update 5 May 2009 I have started a new blog to publish my experiments with ruby-processing http://learning-ruby-processing.blogspot.com

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2