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

Wednesday, 16 March 2011

Exploring context-sensitive L-system (vanilla-processing)

I have just uploaded the latest version of my LSystem Utilities library at project kenai, that now includes tools for working with context sensitive grammars. Here is a simple example included with my utilities, that demonstrates one of the features of a context sensitive lsystem. Update 20th March 2011, I think I might have finally solved the bug in my context sensitive grammar. See version 0.7.0 which I think solves that problem and also allows context sensitivity to scroll around, a behaviour that was effortlessly achieved in my ruby-processing prototype. Note my vanilla processing requires non-context sensitive premis to be a single java char (ie not a java String). The context sensitive premis is a java String, where the middle character is either '<' (means context char before) or '>' (context char follows). The third char of the premis is the one that is replaced, according to the context rules, the first char provides the 'context'.

/**
* cs_test.pde
* Demonstrates a simple context sensitive grammar without ignored
* symbols. No real sketch, just console output that demonstrates
* character moving in the string (without adjusting length).
* NB: you may need to scroll the console to see all the output.
*/
import lsystem.collection.*;
import lsystem.CSGrammar;

CSGrammar grammar; 

void setup() {
  createGrammar();
  testGrammar();
}

void createGrammar() {
  String axiom = "baaaaaaa";  
  grammar = new CSGrammar(this, axiom); // initialize library
  grammar.addRule("b<a", "b");          // add cs replacement rule
  grammar.addRule('b', "a");            // add simple replacement rule  
}

void testGrammar(){
  for (int i = 0; i < 8; i++){
  String production = grammar.createGrammar(i);
  println(production);
  }
}

/**
Test Output, note the string does not grow in length,
but the b character travels along the string.

baaaaaaa
abaaaaaa
aabaaaaa
aaabaaaa
aaaabaaa
aaaaabaa
aaaaaaba
aaaaaaab
*/

This facility could potentially be used in an animation, or to control musical scales?

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