-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurtleInterpreter.h
48 lines (41 loc) · 1.17 KB
/
TurtleInterpreter.h
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
#ifndef TURTLEINTERPRETER_H
#define TURTLEINTERPRETER_H
#include "Turtle.h"
class TurtleInterpreter {
public:
std::vector<Turtle> ts;
explicit TurtleInterpreter(const Turtle &t) {
ts.push_back(t);
};
void Draw(const std::string &s) {
glBegin(GL_LINES);
for (unsigned int i = 0; i < s.length(); i++) {
switch (s[i]) {
case 'f':
ts.back().f();
break;
case 'F':
ts.back().F();
break;
case '+':
ts.back().plus();
break;
case '-':
ts.back().minus();
break;
case '[':
ts.push_back(ts.back());
break;
case ']':
ts.pop_back();
if (ts.size() == 0) {
std::cerr << "TurtleInterpreter Error - more pops than pushes." << std::endl;
exit(1);
}
break;
}
}
glEnd();
}
};
#endif /* TURTLEINTERPRETER_H */