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

Sunday, 8 February 2009

Syntax Highlighting TMTOWTDI

Now I guess there's not much chance of any fellow contributors being vim users, but in case there are there is an ftplugin "processing.vim" available. What is more vim (or cream if you prefer a friendly gui, NB: both editors are available for Windows, if your a Windows user, choose cream then use 'Tools/Add-ons/convert/syntax highlighting to Html' from the menu) supports the code2html conversion, so there's an alternative to using jedit. Scripting fans will know there is also perlscript that can do the code to html conversion.
If you've got python support for vim, (and set the processing documentation path in you vimrc file) you can use the 'K' key to call up the processing documentation (loads in your browser, how cool is that). I think there is history here as developers may well have started development using vim...
So for those of you who like Antony enjoy the console look check out my vim highlighted Star.pde converted to to html http://myweb.tiscali.co.uk/monkstone/html/Star.html. Formatting is done directly in the html ie does not use a css style-sheet or header declaration.
Unlike jedit, where you need to add the code 'syntax' css style elements to the header in the page layout of your blog (remember you only need do this once and it is easy). Thereafter you cut and paste the code between <pre> tags into the edit html box on your blog.
Update 4 May, I've finally succumbed to the console look on my other blog http://martinpchunk68.blogspot.com/

Saturday, 7 February 2009

Spooky Stuff, there is more than one way to do it

Thought I would take a look at Matrix stuff in processing, turns out it works OK with my Saucer class. So as Larry Wall (he of Perl fame) there is definitely more than one way of doing it, take the code to present three saucer images from my chunk68 (3 instances of saucer), compared to this version which just has one saucer with two translation to produce much the same result:-

   1:void setup() {
2: size(300, 250);
3: Saucer saucer = new Saucer(50.0f, 50.0f); // new saucer centre 50.0f, 50.0f
4: smooth();
5: background(11, 17, 67); // space, the final frontier
6: fill(116, 39, 39); // planet fill
7: ellipseMode(CENTER);
8: ellipse(225, -125, 350, 350); // define the planet
9: saucer.setSize(5.0f);
10: saucer.setColor(color(211, 11, 211));
11: saucer.tilt( QUARTER_PI/2);
12: saucer.render(); // render saucer, if used in animation place in draw()
13: pushMatrix(); // store current coordinate system
14: translate(50, 50); // translate coordinate system
15: saucer.setSize(10.0f);
16: saucer.tilt( QUARTER_PI/4);
17: saucer.setColor(color(255, 0, 0));
18: saucer.render();
19: popMatrix(); // restore original coordinate system
20: translate(160, 110); // now do another translation
21: saucer.setSize(15.0f);
22: saucer.tilt(0.0f);
23: saucer.render(); // color is default Saucer color
24:}
25:
26:// Like Larry says there is more than one way to do it (Spooky stuff)


Code for Saucer is unchanged.

Just for a bit of fun now the international season is upon us...

   1:// the ginger_monster.pde aka neil (Darrel knows!!!) to be continued
2:float x = 50;
3:float y = 100;
4:float angle1 = 0.0;
5:float angle2 = 0.0;
6:float angle3 = HALF_PI;
7:float segLength = 50;
8:
9:void setup() {
10: size(200, 200);
11: smooth();
12: strokeWeight(20.0);
13: stroke(0, 100);
14:}
15:
16:void draw() {
17: background(226);
18:
19: angle1 = (mouseX/float(width) - 0.5) * -PI;
20: angle2 = (mouseY/float(height) - 0.5) * PI;
21:
22: pushMatrix();
23: leg(x, y, angle1);
24: leg(segLength, 0, angle2);
25: foot(segLength, 0, -angle3);
26: popMatrix();
27:}
28:
29:void leg(float x, float y, float a) {
30: translate(x, y);
31: rotate(a);
32: line(0, 0, segLength, 0);
33:}
34:
35:void foot(float x, float y, float a) {
36: translate(x, y);
37: rotate(a);
38: line(0, 0, segLength/4, 0);
39:}

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