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

Saturday, 15 August 2009

Recursive call with probabalistic endpoint

I've been playing with the 'context free art' program cfdg quite a bit recently. So I've neglected what sent me there in the first place, which was the DSL cfdg ruby-processing implementation by Jeremy Ashkenas. Here I've written a stand alone ruby-processing script that mirrors one of the way infinite recursion is controlled in cfdg. The main way of preventing infinite recursion (which is used a lot in context free art) is to a have a lower size limit for the terminal elements (SQUARE or CIRCLE), and to have them reduce in size during the recursive loop. The second approach, which I have mirrored here is to have a low probability empty rule that will also terminate:-

REDUCE = 0.999;
def setup()
  size(400, 400)
  translate(100, 330)
  rotate(0.3)
  fill(255, 0, 0, 0)
  background(0)
  no_stroke()  
  smooth()
  fill(255, 0, 0, 20) # transparency makes for almost '3d' look
  srand = rand(999)  
  shell(srand, -0.008, 1.5, 25)
end
def shell(first, rot, disp, sz)
  sec = rand(999)
  if (sec == first) then
    save_frame("probability.png")
  else  
    sz *= REDUCE;
    disp *= REDUCE;
    translate(disp, 0)
    rotate(rot)
    ellipse(disp, 0, sz, sz)
    shell(sec, rot, disp, sz) # recursive call with updated random
  end
end

By its probabilistic nature this script will sometimes produce nothing, and occasionally it will crash at the java stack limit, here is one of the successful runs:-


You could always increase the size of the java stack as I did here. There are some instructions on how to do it at the processing discourse (alternative implementations) written by Jeremy Ashkenas:-
.... you can try increasing the java stack size. Create a "data" folder next to all the sketches and the library, and add a "java_args.txt" file in there that reads "-Xss8M".... that should do it, it worked for me.

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