diff --git a/index.html b/index.html index e46cc24..9c289f3 100644 --- a/index.html +++ b/index.html @@ -7,9 +7,9 @@ L-systems - - - + + + diff --git a/libs/lsystem.js b/src/lsystem.js similarity index 100% rename from libs/lsystem.js rename to src/lsystem.js diff --git a/src/scenes.js b/src/scenes.js index d0155b3..a87619e 100644 --- a/src/scenes.js +++ b/src/scenes.js @@ -6,6 +6,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 600, decay: 4, @@ -20,6 +21,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 600, decay: 4, @@ -34,6 +36,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 600, decay: 2, @@ -49,6 +52,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 100, decay: 2, @@ -63,6 +67,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, @@ -77,6 +82,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, @@ -91,6 +97,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, @@ -105,6 +112,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, @@ -119,6 +127,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, @@ -133,6 +142,7 @@ const SCENES = [ '-': '-', '+': '+' }, + maxDerivations: 5, angle: 90, distance: 50, decay: 2, diff --git a/src/sketch.js b/src/sketch.js index 49999ef..abb7aaa 100644 --- a/src/sketch.js +++ b/src/sketch.js @@ -7,6 +7,7 @@ const BACKGROUND_COLOR = [0, 0, 0]; // define L-system state +let clicks = 1; let currentScene = 0; let lsystem; @@ -40,36 +41,20 @@ function draw() } -/** - * p5.js key pressed callback. - */ -function keyPressed() -{ - // right arrow is pressed: move to next scene - if (keyCode === RIGHT_ARROW) - { - // get next scene index - currentScene + 1 === SCENES.length ? currentScene = 0 : currentScene++; - - // setup next scene - loadScene(); - - // call p5.js drawing function - redraw(); - } -} - - /** * p5.js mouse clicked callback. */ function mouseClicked() { - // derivate next L-system state - lsystem.derive(); + if (clicks === SCENES[currentScene].maxDerivations) + { + nextScene(); + clicks = 0; + } - // call p5.js drawing function - redraw(); + else + nextDerivation(); + clicks += 1; } @@ -93,3 +78,32 @@ function loadScene() scene.decay ); } + + +/** + * Forward sketch to next scene. + */ +function nextScene() +{ + // get next scene index + currentScene + 1 === SCENES.length ? currentScene = 0 : currentScene++; + + // setup next scene + loadScene(); + + // call p5.js drawing function + redraw(); +} + + +/** + * Get L-system next derivation. + */ +function nextDerivation() +{ + // derivate next L-system state + lsystem.derive(); + + // call p5.js drawing function + redraw(); +} diff --git a/libs/stringbuffer.js b/src/stringbuffer.js similarity index 100% rename from libs/stringbuffer.js rename to src/stringbuffer.js diff --git a/libs/turtle.js b/src/turtle.js similarity index 100% rename from libs/turtle.js rename to src/turtle.js