Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Wednesday 1 September 2010

Using the Toxi Processing Libraries in ruby processing

Toxi aka Karsten Schmidt has created some fantastic libraries for processing that make some otherwise difficult things very easy. Here is just one example that I've tried that could be very useful in generative art.  To use processing libraries in your ruby processing sketch place each jar in folder of the same name as the jar. Then put that folder in library folder, where you've saved the sketch.


#
# <p>Hello Gray-Scott is a very basic demonstration of the underlying
# reaction-diffusion simulation. This model can be used to produce
# a wide variety of patterns, both static and animated and is therefore
# well suited for being combined with other generative techniques.</p>
#
# <p><strong>usage:</strong></p>
# <ul>
# <li>click + drag mouse to draw dots used as simulation seed</li>
# <li>press any key to reset</li>
# </ul>
#

#
# Copyright (c) 2010 Karsten Schmidt
#
# This demo & library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# http://creativecommons.org/licenses/LGPL/2.1/
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

class HelloGrayScott < Processing::App
  load_libraries 'simutils','toxiclibscore'
  include_package "toxi.sim.grayscott"
  include_package "toxi.math"

  attr_reader :gs

  def setup()
    size(256,256)
    @gs=GrayScott.new width, height, false
    @gs.set_coefficients 0.023, 0.074, 0.095, 0.03
  end

  def draw()
    @gs.set_rect mouse_x, mouse_y, 20, 20 if mouse_pressed?
    load_pixels
    10.times { @gs.update(1) }

    gs.v.length.times do |i|
        val = gs.v[i]*768
        min = (255 <= val)? 255 : val       # processing convenience min(x, y) doesn't work for me
        col= 255 - min.to_i
        pixels[i]=col<<16|col<<8|col|0xff000000
      end
    update_pixels
  end

  def key_pressed
    @gs.reset
  end

end






Reaction Diffusion at Wikipedia

Other interesting links:-

A 3D example in java

A very nice 2D example

http://toxiclibs.org/2010/02/simutils-grayscott/

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2