jashkenas / ruby-processing

Code as Art, Art as Code. Processing and Ruby are meant for each other.

Home Page:http://github.com/jashkenas/ruby-processing/wikis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to load pure ruby libraries?

97-109-107 opened this issue · comments

I'm trying to figure out how to load a pure ruby library into a sketch.
The readme doesn't seem to have an answer, I looked into library_loader.rb and found this comment:

# For pure ruby libraries.
# The library should have an initialization ruby file
# of the same name as the library folder.

But this doesn't help me much. How should the 'library' folder structure look like and how to import the library?

Thanks

In the examples there is a ruby library called hilbert.rb, this has been placed in a folder hilbert.
Then you can use:-

load_libraries 'hilbert'

to load the library/libraries

I tried mimicking that structure to use perlin_noise library.
The core file that is the equivalent of hilbert.rb contains the following:

require 'rubygems'
require 'matrix'
require 'version'
require 'curve'
require 'gradient_table'
require 'noise'

the rest of the .rb files that make up for the gem are placed inside another directory called perlin. I experimented with placing them inside that directory (one level down from the equivalent of hilbert) and besides the equivalent of hilbert.rb
This is the error reported

uninitialized constant Perlin::Noise

Which leads me to believe that the library isn't loaded correctly.

@97-109-107 How did you install the gem? This worked for me (I actually needed sudo on archlinux) note needs jruby installed (Instructions for pure ruby library does not refer to gems)

jruby -S gem install perlin_noise

rp5 run --jruby perlin_test.rb (you should use external jruby to run the sketch)


require 'perlin_noise'

def setup
  size 200, 200
  n1d = Perlin::Noise.new 1
  0.step(100, 0.01) do |x|
    puts n1d[x]
  end
end

NB: That is all the code you now need since "bare" sketches are the new standard for ruby-processing
Worked for me with my development version of ruby-processing https://github.com/monkstone/ruby-processing.
If that doesn't work take desperate measures:-

  1. Install ruby-processing using jruby:-
sudo jruby -S gem install ruby-processing # (do the same for libraries you wish to run) 2. Run sketches with rp5 fired up from jruby jruby -S rp5 run --jruby ruby_perlin_force.rb

@mcfiredrill does this solve your problem to?

also see worked example here