Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Saturday, 15 August 2009

An alternative way of limiting recursion

Setting a smallest size is not the only way to limit recursion in context free, the second way is to have an empty rule (ie no shape). I wanted to explore an equivalent situation using processing. Here I have re-written my 'processing spiral' to have a probalistically determined end point (note for that reason you will sometimes not get what you are looking for. Also there is finite chance of getting nothing at all or otherwise hit the recursion limit.

   1 float REDUCE = 0.999;
   2 
   3 void setup(){
   4   size(400, 400);
   5   translate(100, 330); 
   6   rotate(0.3);
   7   fill(255, 0, 0, 0);
   8   background(0);
   9   noStroke();   
  10   smooth();
  11   fill(255, 0, 0, 20); // transparency makes for almost '3d' look
  12   int srand = int(random(0, 999));  
  13   shell(srand, -0.008, 1.5, 25);
  14 }
  15 
  16 void shell(int first, float rot, float disp, float sz){
  17   int sec = int(random(0, 999));
  18   if (sec == first){
  19     saveFrame("probability.png");
  20     //exit();
  21   }
  22   else{   
  23     sz *= REDUCE; 
  24     disp *= REDUCE;
  25     translate(disp, 0);
  26     rotate(rot);
  27     ellipse(disp, 0, sz, sz);
  28     shell(sec, rot, disp, sz); // recursive call with updated random
  29   }
  30 }
  31 


Here is one of the "better" results of running this applet (PS I increased the maximum available memory to 2500 Mb in the processing ide for this run).

No comments:

Post a Comment

Followers

Blog Archive

About Me

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