-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_overview.py
executable file
·125 lines (92 loc) · 3.29 KB
/
create_overview.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/python
# make it possible to run script on shell without X
import matplotlib as mpl
mpl.use('Agg')
import sys
import waveshaper.tables as tables
import waveshaper.Painter as Painter
import io
import base64
from waveshaper.MatplotlibSurface import MatplotlibSurface
from waveshaper.RenderInstruction import RenderInstruction
from waveshaper.InstructionSequence import InstructionSequence
from waveshaper.EnvironmentChangeInstruction import EnvironmentChangeInstruction
def plot_symbol(sym):
s = MatplotlibSurface()
p = Painter.Painter(s)
i = RenderInstruction(sym, 1)
i.render_symbol(p)
i.render_symbol_bg(p)
s.ax.plot([0, 1], [.5, .5], linewidth=.2, color='grey')
s.ax.plot([0, 1], [-.5, -.5], linewidth=.2, color='grey')
s.ax.plot([0.2, 0.2], [.6, -.6], linewidth=.2, color='grey')
s.ax.plot([0.8, 0.8], [.6, -.6], linewidth=.2, color='grey')
s.ax.set_xlim([0, 1])
s.ax.set_ylim([-.6, .6])
imgdata = io.BytesIO()
s.fig.set_size_inches([.5, .6])
s.fig.savefig(imgdata, format='png')
imgbase64 = base64.b64encode(imgdata.getvalue()).decode('utf-8')
return imgbase64
def plot_transition(sym1, sym2):
s = MatplotlibSurface()
p = Painter.Painter(s)
i = [
EnvironmentChangeInstruction('color', 'red'),
RenderInstruction(sym1, 1),
EnvironmentChangeInstruction('color', 'green'),
RenderInstruction(sym2, 1),
]
seq = InstructionSequence(i)
try:
seq.execute(p)
except KeyError:
raise
s.ax.plot([0, 2], [.6, -.6], linewidth=.2, color='red')
s.ax.plot([0, 2], [.5, .5], linewidth=.2, color='grey')
s.ax.plot([0, 2], [-.5, -.5], linewidth=.2, color='grey')
s.ax.plot([1, 1], [.6, -.6], linewidth=.2, color='grey')
s.ax.plot([0.8, 0.8], [.6, -.6], linewidth=.2, color='grey')
s.ax.plot([1.2, 1.2], [.6, -.6], linewidth=.2, color='grey')
s.ax.set_xlim([0, 2])
s.ax.set_ylim([-0.6, 0.6])
imgdata = io.BytesIO()
s.fig.set_size_inches([1, .6])
s.fig.savefig(imgdata, format='png')
imgbase64 = base64.b64encode(imgdata.getvalue()).decode('utf-8')
return imgbase64
def plot_symbols(f):
print('<table>', file=f)
print('<tr>', file=f)
for sym in sorted(tables.symbols.keys()):
print('<td style="text-align:center">{0}</td>'.format(sym), file=f)
print('</tr><tr>', file=f)
for sym in sorted(tables.symbols.keys()):
imgdata = plot_symbol(sym)
tr = '<td><img src="data:image/png;base64,{img}"</img></td>'.format(img = imgdata)
print(tr, file=f)
print('</tr>', file=f)
print('</table>', file=f)
def plot_transitions(f):
print('<table>', file=f)
print('<tr><td></td>', file=f)
for sym in sorted(tables.symbols.keys()):
print('<td style="text-align:center">{0}</td>'.format(sym), file=f)
print('</tr>', file=f)
for sym1 in sorted(tables.symbols.keys()):
print('<tr>', file=f)
print('<td>{0}</td>'.format(sym1), file=f)
for sym2 in sorted(tables.symbols.keys()):
imgdata = plot_transition(sym1, sym2)
tr = '<td><img src="data:image/png;base64,{img}"</img></td>'.format(img=imgdata)
print(tr, file=f)
print('</tr>', file=f)
def main():
with open('overview.html', mode='w') as f:
print('<html><body>', file=f)
plot_symbols(f)
print('<br /><br />', file=f)
plot_transitions(f)
print('</body></html>', file=f)
if __name__ == '__main__':
sys.exit(main())