-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
88 lines (66 loc) · 2.73 KB
/
Copy pathparser.py
File metadata and controls
88 lines (66 loc) · 2.73 KB
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
from display import *
from matrix import *
from draw import *
ARG_COMMANDS = [ 'line', 'scale', 'translate', 'xrotate', 'yrotate', 'zrotate', 'circle', 'bezier', 'hermite', 'box', 'sphere', 'torus' ]
def parse_file( f, points, transform, screen, color ):
commands = f.readlines()
c = 0
while c < len(commands):
cmd = commands[c].strip()
if cmd in ARG_COMMANDS:
c+= 1
args = commands[c].strip().split(' ')
i = 0
while i < len( args ):
args[i] = float( args[i] )
i+= 1
if cmd == 'line':
add_edge( points, args[0], args[1], args[2], args[3], args[4], args[5] )
elif cmd == 'circle':
add_circle( points, args[0], args[1], 0, args[2], .01 )
elif cmd == 'bezier':
add_curve( points, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], .01, 'bezier' )
elif cmd == 'hermite':
add_curve( points, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], .01, 'hermite' )
elif cmd == 'box':
add_box( points, args[0], args[1], args[2], args[3], args[4], args[5] )
elif cmd == 'sphere':
add_sphere( points, args[0], args[1], 0, args[2], .01 )
elif cmd == 'torus':
add_torus( points, args[0], args[1], 0, args[2], args[3], .01 )
elif cmd == 'scale':
s = make_scale( args[0], args[1], args[2] )
matrix_mult( s, transform )
elif cmd == 'translate':
t = make_translate( args[0], args[1], args[2] )
matrix_mult( t, transform )
else:
angle = args[0] * ( math.pi / 180 )
if cmd == 'xrotate':
r = make_rotX( angle )
elif cmd == 'yrotate':
r = make_rotY( angle )
elif cmd == 'zrotate':
r = make_rotZ( angle )
matrix_mult( r, transform )
elif cmd == 'ident':
ident( transform )
elif cmd == 'apply':
matrix_mult( transform, points )
elif cmd == 'clear':
r = new_matrix(0, 0)
points = r
elif cmd in ['display', 'save' ]:
screen = new_screen()
draw_lines( points, screen, color )
if cmd == 'display':
display( screen )
elif cmd == 'save':
c+= 1
save_extension( screen, commands[c].strip() )
elif cmd == 'quit':
return
else:
if cmd[:1] != "#":
print 'Invalid command: ' + cmd
c+= 1