manko
07-25-2004, 05:50 PM
I extracted this from some code I wrote for generating l-system strings. I use these to create floral patterns. There is an idea of having "age" information, so only if a node existed for some time (number of rewriting cycles) it will e.g. produce a flower. I just don t arrive how to implement independently increasing indices in JavaScript..
I explain my problem using a wildcard (*).. if each cycle I would like a character "I" to be rewritten by two productions:
I(*) --> I(*+1); //the same I, aged by +1
I(*) --> I (1); //a new I, with age 1
..I don t get how to do this with JavaScript...I always end up with kind of global variables like the x in my code..
thanks a lot for any help..I would love to continue with my design..I just have the feeling I m stuck in a wrong way of facing the problem..
var x=0;
var list = new Array();
var newList = new Array("I("+x+")");
var cycle;
var cycleEnd = 5;
for (cycle =1; cycle<=cycleEnd; cycle++)
{
//show the list before rewriting
alert("Cycle "+ cycle +" : " + newList.join(" "));
list= newList;
var i=0;
for(z=0;z<list.length; z++)
{
switch(list[z])
{
case "I("+x+")":
newList[i]= "I("+x+")"; i++;
x += 1;
newList[i]= "I("+x+")"; i++;
}
}
}
I explain my problem using a wildcard (*).. if each cycle I would like a character "I" to be rewritten by two productions:
I(*) --> I(*+1); //the same I, aged by +1
I(*) --> I (1); //a new I, with age 1
..I don t get how to do this with JavaScript...I always end up with kind of global variables like the x in my code..
thanks a lot for any help..I would love to continue with my design..I just have the feeling I m stuck in a wrong way of facing the problem..
var x=0;
var list = new Array();
var newList = new Array("I("+x+")");
var cycle;
var cycleEnd = 5;
for (cycle =1; cycle<=cycleEnd; cycle++)
{
//show the list before rewriting
alert("Cycle "+ cycle +" : " + newList.join(" "));
list= newList;
var i=0;
for(z=0;z<list.length; z++)
{
switch(list[z])
{
case "I("+x+")":
newList[i]= "I("+x+")"; i++;
x += 1;
newList[i]= "I("+x+")"; i++;
}
}
}