-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
33 lines (23 loc) · 752 Bytes
/
Copy pathplot.py
File metadata and controls
33 lines (23 loc) · 752 Bytes
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
import svg
from evaluate import Evaluator
from basic import Point, BasicNamespace
def plot_point(namespace, f, tag, x, y):
namespace.set(tag, Point(x, y))
def plot_line(namespace, f, p1, p2):
svg.plot_line(f, p1, p2)
def plot_circle(namespace, f, pos, radius):
svg.plot_circle(f, pos, radius)
def do_(namespace, f, *args):
pass # args have been plotted as a side-effect
top_level_namespace = BasicNamespace({
'plot': do_,
'point': plot_point,
'line': plot_line,
'circle': plot_circle
})
def plot(filename, w, h, tree):
with open(filename, 'w') as f:
f.write(svg.xml_prolog)
svg.svg_open(f, w, h)
Evaluator(top_level_namespace, [f]).evaluate(tree)
f.write('</svg>')