Ruby-Processing bridges the elegant, beginner-friendly syntax of the Ruby programming language with the powerful visual capabilities of the Processing environment. By utilizing JRuby (Ruby running on the Java Virtual Machine), it wraps standard Java-based Processing into an expressive, dynamically typed scripting language. This eliminates rigid boilerplate like declaring types or voids, letting you quickly script everything from generative art and interactive exhibits to data visualizations. Why Choose Ruby-Processing?
No Strict Typing: You don’t have to manage differences between floats, ints, or voids to draw shapes.
Clean Code: Ruby’s object-oriented nature makes complex algorithmic structures highly readable.
Full Java Ecosystem: Access any existing standard Java Processing library natively through JRuby.
Interactive Tooling: Modern iterations like JRubyArt or propane offer fast reloads for rapid artistic prototyping. The Core Skeleton
Every dynamic visual art piece in Ruby-Processing revolves around two foundational methods:
setup: Runs once at start to set the canvas window size, background colors, and initial variables.
draw: Loops continuously (usually 60 times per second) to update positions and render changing visuals on screen.
Here is a minimalist example of a functioning sketch that draws a circle tracking the user’s mouse:
class MouseFollower < Processing::App def setup size(600, 600) # Sets the window width and height background(20, 20, 30) # Sets a dark blue background end def draw # Fills the shape with semi-transparent white for a trailing effect fill(255, 255, 255, 50) no_stroke # Removes borders around the shape # Draws an ellipse at the cursor’s coordinates ellipse(mouse_x, mouse_y, 40, 40) end end Use code with caution. Installation Steps
Setting up the project requires a few configuration steps because it links Ruby and Java components together.
Install Java: Ensure the Java Development Kit (JDK) is active on your machine.
Install the Gem: Download the tool wrapper via your terminal terminal. gem install ruby-processing Use code with caution.
Download JRuby Engines: Run the built-in utility to download the required backend .jar files. rp5 setup install Use code with caution.
Execute Your Art: Save your script as my_art.rb and use the built-in runner tool to view it: rp5 run my_art.rb Use code with caution.
(Note: Depending on your current system configurations, you may prefer using its updated successor tooling, JRubyArt or propane, which simplify the installation steps into a single command like k9 –install). Key Visual Building Blocks
Coordinate System: The window coordinates begin at (0,0) in the top-left corner. Moving right increases X, moving down increases Y.
State Operations: Use push_matrix and pop_matrix to temporarily move, scale, or rotate the grid environment for intricate geometric patterns.
Math and Randomness: Leverage Ruby’s native mathematical toolset paired with Processing’s noise() function to create smooth, natural Perlin noise textures instead of rigid, blocky random shapes. Drawing with Processing and Ruby – SitePoint
Leave a Reply