Ruby-Processing
- Started
- Last post
- 39 Responses
- stewdio
Been having fun with this for 2 weeks now and thought I should post about it :
Ruby-Processing is a method for using the Processing library (http://processing.org) in Ruby; a typographically clean and conceptually elegant programming language that I much prefer to Processing's native language: Java. If you're on OS X it's very simple to install.
1. Open up Terminal. It's a program in your Applications > Utilities folder.
2. Paste this into Terminal and hit enter :
sudo gem install ruby-processing3. Type in your admin password when it asks. That's it. Done. You have Ruby-Processing.
ShellHere is a little app that opens up a new Terminal window to whatever folder location I have open in Finder. So I navigate to the folder that contains my Ruby-Processing app, hit the ShellHere button, and I'm good to go in Terminal.
http://etresoft.org/shellhere.ht…TextMate is my text editor of choice. Even though it costs money I recommend it over TextWrangler, etc. If you've done Ruby on Rails you're likely already familiar with it.
http://macromates.comOk. So now you know how to install Ruby-Processing, you know a handy free app to pop open Terminal to the folder your Ruby-Processing app is in, but you need to write a program and run it somehow . . . I'll post that in just a sec. In the meantime, here's the Ruby-Processing Getting Started page :
http://wiki.github.com/jashkenas…
- stewdio0
QBN is going to destroy the pretty code indentation here, but the program will still work. Getting a spinning red cube is just another three steps away :
1. Copy and paste the code into a new *plain* text document and save it as "MyCubes.rb"
2. Open Terminal to the folder where your MyCubes.rb is located.
3. Paste this into Terminal and hit enter :
rp5 run MyCubes.rbThat's it. You should see a red cube spinning in black space. When you're done being mesmerized hit Command+Q to quit. Here's the code for it :
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
class MyCubes < Processing::App
load_library :opengldef setup
size 640, 360, OPENGL
frame_rate 30@x_degree = 45
@y_degree = 0
no_strokeend
def draw
background 0
lights
push_matrixtranslate width / 2, height / 2, 0
rotate_x radians( @x_degree )
rotate_y radians( @y_degree )fill 255, 0, 0, 240
box 100pop_matrix
@x_degree = ( @x_degree + 1 ).modulo 360
@y_degree = ( @y_degree + 2 ).modulo 360
endend
MyCubes.new :title => "My Cubes!"- Thanks!lukus_W
- Thanks for the ShellHere tip as well. Handy little app.ctcliff
- you could always just post the code on pastie.org or gist....(github)sublocked
- lukus_W0
This is a nice guide for ruby:
- lukus_W0
Not really for the ruby version of processing, but useful nevertheless:
- stewdio0
If you already know Processing every one of those commands should be familiar to you. They're just the "Ruby-ized" version. (Java makes a lot of use of CamelCase variable names, while Ruby prefers under_scores instead.) Here's a complete list of Processing commands : http://processing.org/reference
And here's everything you need to know about Ruby.
http://www.ruby-lang.org/en/docu…I highly recommend their "Ruby in Twenty Minutes" tutorial. They're not kidding. It's quick. And it makes sense.
http://www.ruby-lang.org/en/docu…
- lukus_W0
This is a nice editor for ruby - it's new, and improving all the time .. works a bit like textmate (uses textmate bundles), and it's free. Check it out.
- stewdio0
Ok. If you want to get all psychedelic with your color theory try this update and save it as MyCubes2.rb (or whatever you want to call it, it doesn't matter). And here's a little HSB-related color review while you're at it :
http://en.wikipedia.org/wiki/HSL…. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
class MyCubes < Processing::App
load_library :opengldef setup
size 640, 360, OPENGL
frame_rate 30
@x_degree = 45
@y_degree = 0
@color_hue = 0
color_mode HSB, 360
no_stroke
enddef draw
background_hue = ( @color_hue + 180 ).modulo 360
background background_hue, 360, 360, 360
lights
push_matrixtranslate width / 2, height / 2, 0
rotate_x radians( @x_degree )
rotate_y radians( @y_degree )
fill @color_hue, 360, 360, 320
box 100pop_matrix
@x_degree = ( @x_degree + 1 ).modulo 360
@y_degree = ( @y_degree + 2 ).modulo 360
@color_hue = ( @color_hue + 1 ).modulo 360
endend
MyCubes.new :title => "My COLORFUL Cubes!"
- stewdio0
Ruby + Processing = RubyProcessing
Or for the more visual crowd :
.
+ Processing
http://processing.org= RubyProcessing
http://wiki.github.com/jashkenas…
- drgss0
"typographically clean programming language"
what?- evil language purists who've never had to write kludge code to make a deadline!vaxorcist
- Vaxorcist, you are mistaken.stewdio
- I may open my mind.... I worked with a ROR egotist/cult member who gave me PTSD about ruby....vaxorcist
- Good point. I've run into that too. (I hope I don't come off that way!)stewdio
- Ruby programmers seem very cool... ROR cult members seem not to use Ruby outside ROR....vaxorcist
- detritus0
I'm barely getting to grips with Processing Java running local, hacking others' code - I've still no clue what Ruby actually *is*.
- stewdio0
@drgss. Yes. Typographically clean. Compare Ruby to Java for instance and you'll see that Ruby does a great job getting rid of excessive semicolons, curly braces, parenthesis, etc. There's a real flexibility with how you write Ruby code so instead of just writing code that the computer can understand you can write code that looks clean and better communicates to other humans what your intent is. There's a great quote from the book Structure and Interpretation of Computer Programs: "Programs should be written for people to read, and only incidentally for machines to execute."
I have a deep appreciation for clean coding. When I work with other designers and they hand me code that is concise and legible it draws my instant respect.
- lukus_W0
Ruby's a really nice programming language - said to be easier to use than Java ..
With many high-level languages, there are a lot of weird quirks that are necessarily to write code that won't break.
Because of this, a lot of the time, a beginner often can't get to grips with creating anything worthwhile, because they need to know about things like 'casting' and 'precedence', the number of bits each datatype is going to consume or where to add a semicolon to end each statement. The details get in the way.
With ruby, a lot of the time this knowledge isn't needed - stuff just works. It's a much nicer language to code in.
- lukus_W0
I always like this guy's processing work - but it's a bit old now maybe:
- lukus_W0
This guy's stuff is amazing .. the pic is a still from a algorithmically generated animation of Mt. Fuji created for the Wing Luke Asian Museum.
- stewdio0
@detritus
Ruby is a fairly young programming language, first publicly released in 1995. It was created by Japanese programmer Yukihiro "Matz" Matsumoto. And if you're running OS X you already have Ruby installed :) For more historical info I found the Ruby Wiki page to be decent: http://en.wikipedia.org/wiki/Rub…)
Ruby gained significant popularity with the rise of Ruby on Rails. (Rails is a web application framework written in Ruby.) In fact, web searches for things having to do with Ruby will usually land you on a page that's actually discussing Rails. Here's the homepage for RoR: http://rubyonrails.org
But Ruby is good for more than just building websites. Right now I'm excited about using it to create animated data visualizations. Ruby-Processing takes the commands and libraries I was used to in Processing and allows me to use them in Ruby. That means I can hit the ground running. And I found programming in Ruby to be much more rewarding that coding in Java (Processing).
- stewdio0
Made with Ruby-Processing (Using OpenGL).
http://ashkenas.com/codework/a_f…- Wow, that must be the nicest looking color coding I've ever seen;)ukit
- the exe just didnt open or anything for me : /mikotondria3
- lukus_W0
I think the live coding feature could be great for visualisations / vjing.
- I used http://www.pawfal.or… for this a while back.lukus_W
- This could be interesting....vaxorcist
- acrossthesea0
I always wanted to get into this. How's the learning curve coming from an AS3 background?
- stewdio0
@acrossthesea
Forget learning curves ;) Just follow my instructions at the top of this post and in about 5 minutes you'll be playing with a red cube rotating in space. And you'll want to mess with it.
That's all you need, the urge to mess with the code. Little thoughts like "I bet I could make the cube larger." Or "I wonder if I can just copy what he's doing with the X-axis and make it rotate on the Z-axis instead." Before you know it you'll be tackling much bigger stuff. You'll be golden.
- Thanks, I'll give it a shot!acrossthesea
- Awesome :)stewdio
- ukit0
Twitter, Github, YellowPages dot com and Hulu are all written in Ruby on Rails to various degrees.
For some reason Ruby inspires serious devotion from its users. I used to work with a programmer who was really into it. He talked about Ruby like it was his girlfriend, kinda weird if you ask me ;)
- Ruby is nice, RoR has a very steep learning curve after the basicscomicsans