-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
68 lines (56 loc) · 1.09 KB
/
cli.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from compilateur_logo import compile_logo
filename = sys.argv[1]
commands = []
with open (filename) as inputfile:
for line in inputfile:
commands.append(line.strip().split())
print """
<script src="processing.js"></script>
<script type="text/processing" data-processing-target="processing-canvas">
float x;
float y;
int dir;
void setup(){{
size(1000, 1000);
noLoop();
}}
void draw(){{
background(255);
translate(250, 250);
executeLogoCommands();
drawTurtle();
}}
void drawTurtle(){{
pushMatrix();
translate(x, y);
rotate(radians(90+dir));
int l = 20;
triangle(0, -l, l/2, 0, -l/2, 0);
popMatrix();
}}
void av(int pas) {{
float pasx = pas * cos(radians(dir));
float pasy = pas * sin(radians(dir));
float new_x = x + pasx;
float new_y = y + pasy;
line(x, y, new_x, new_y);
x = new_x;
y = new_y;
}}
void td(float angle) {{
dir += angle;
}}
void tg(float angle) {{
dir -= angle;
}}
void origin() {{
x = 0;
y = 0
}}
void executeLogoCommands(){{
{}
}}
</script>
<canvas id="processing-canvas"></canvas>
""".format(compile_logo(commands))