Dave Perrett

Messing Around With Ruby-processing, Take 5

java, music, processing, programming, ruby

I’ve been spending quite a bit of time playing with ruby-processing (and processing in general) recently. It’s also been my first exposure to JRuby which has been a bit of an eye-opener, in terms of the sheer number of Java libraries that it makes available in Ruby.

All the fun stuff in processing seems to be OpenGL-related, and after a lot of research the easiest way to dig in ended up being the GLGraphics Java library, which was made specifically for use in processing.

To get the ‘rainbow’ coloring effect I originally tried to generate a list of colors algorithmically, which turned out to be a largely brown-ish mess and not very attractive. I ended up doing an image search for ‘rainbow spectrum’ on Google, picking a likely-looking image and scanning the pixels horizontally one by one to get a list of colors, and am reasonably happy with the result. Some of the yellows look pretty over-exposed when doing ‘neon’-type stuff, so I’ll have to cut out some of the brighter colors down the track sometime.

The biggest challenge making these videos turned out to be rendering an even 30fps and syncing with audio to create a video later via ffmpeg. I ended up adapting davbol’s sample code from this thread to ruby-processing.

To get the sliding effect between ‘scenes’ I did a second pass through the track to render one ‘scene’ ahead, and used MiniMagick to merge each set of two frames together. This would be possible in pure Processing but was looking fairly fiddly, so I’m sticking with some old-school image processing for now.

I mailed Rebecca Brandt to check if it was alright to use her music, and got a lovely email back:

That’s totally fine for you to keep the video up as long as it’s clear it’s my music and you are not the copyright holder… Youtube often shuts down videos if music is not properly licensed, but because you emailed me about it (and seem really nice!) of course I’ll give you permission.


If you have a spare $10 I highly recommend you hit her up on BandCamp or iTunes.

Most of the background images are from /r/humanporn.