xxxxxxxxxx
// Lindenmayer systems
var thestring = 'A'; // the starting string ("axiom")
var therules = [];
// rules: what am i looking for? what am i replacing it with?
therules[0] = ['A', 'B'];
therules[1] = ['B', 'BCA'];
therules[2] = ['C', 'ADB'];
therules[3] = ['D', 'CAD'];
var numproductions = 5;
var ptr = 0;
var Asnd, Bsnd, Csnd;
function preload()
{
Asnd = loadSound('A.mp3');
Bsnd = loadSound('B.mp3');
Csnd = loadSound('C.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
// triple loop:
for(let i = 0;i<numproductions;i++)
{
var outstring = '';
for(let j = 0;j<thestring.length;j++)
{
for(let k = 0;k<therules.length;k++)
{
var ismatch = 0;
if(thestring.charAt(j)==therules[k][0]) // MATCH
{
outstring+=therules[k][1]; // copy of the second half
ismatch=1;
break;
}
}
if(ismatch==0) outstring+=thestring.charAt(j);
}
thestring=outstring;
console.log(thestring);
}
frameRate(5);
}
function draw() {
background(0);
fill(255);
textSize(60);
var c = thestring.charAt(ptr);
text(c, width/2, height/2);
if(c=='A') Asnd.play();
if(c=='B') Bsnd.play();
if(c=='C') Csnd.play();
ptr = (ptr+1)%thestring.length;
}