-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsystem.js
51 lines (44 loc) · 993 Bytes
/
lsystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* L-System abstraction.
*/
class LSystem
{
/**
* Constructor.
*
* @constructor
*
* @param {string} axiom - L-system inital axiom
* @param {Object} ruleset - L-system ruleset
*/
constructor(axiom, ruleset)
{
// store components
this.axiom = axiom;
this.ruleset = ruleset;
this.buffer = new StringBuffer()
this.steps = 0;
// initialize buffer
this.buffer.insert(this.axiom);
}
/**
* Exposes system current buffer state.
*
* @returns {string[]} - current buffer state
*/
get state()
{
return this.buffer.state;
}
/**
* Derives next construction according to my ruleset.
*/
derive()
{
// derivate each token of construction
for (let token of this.buffer.flush())
{
this.buffer.insert(this.ruleset[token]);
}
}
}