-
Make switch/case expression choose any option except the current one?
After doing the Workbench L-System tutorial, I’ve been trying to modify the script so that the path doesn’t double back on itself. My goal is create a script generated paths that sort of looks like growing circuitry. Below is the code from the tutorial. I believe this involves making the switch(r) function remember it’s current case and choose any case that isn’t that. However, after researching expressions and javascript switch/case functions, this is clearly above my current coding ability. Anyone know how to solve this, or point me in the right direction? I’m a bit stumped. I’ve also attached a screenshot with the bits where the path backtracks on itself I’m trying to get rid of.
s = thisComp.layer("Controller").effect("Random Seed")("Slider");
n = thisComp.layer("Controller").effect("Steps")("Slider");
l = thisComp.layer("Controller").effect("Max Length")("Slider");
seedRandom(s, true);
var pts = [];
var x = y = 0;
pts.push([x,y]);
for(i = 0; i < n; i++) {
var d = Math.floor(random(l));
var r = Math.floor(random(4));
switch(r) {
case 0:
x += d;
break;
case 1:
y += d;
break;
case 2:
x -= d;
break;
case 3:
y -= d;
break;
}
pts.push([x,y]);
}
createPath(pts, [], [], false);
