本文整理汇总了Python中mdl.parseFile函数的典型用法代码示例。如果您正苦于以下问题:Python parseFile函数的具体用法?Python parseFile怎么用?Python parseFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(filename):
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
num_frames,basename,shading_mode,ambient = first_pass(commands)
frames = second_pass(commands,num_frames)
lights = []
for s in symbols:
if s[0] == 'light': lights.append(s[1])
env = {}
env["shading_mode"] = shading_mode
env["ambient"] = ambient
env["lights"] = lights
if num_frames > 1 and not os.path.exists("anim"):
os.makedirs("anim")
for frame,i in zip(frames,range(len(frames))):
print i,frame
screen = run_frame(commands,frame,env)
if num_frames > 1:
save_ppm(screen, "anim/"+basename+("%03d"%i)+".ppm")
示例2: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
stack = [ tmp ]
screen = new_screen()
for command in commands:
if command[0] = "push":
stack.append(stack[len(stack) - 1])
elif command[0] = "pop":
stack = stack[:len(stack) - 1]
示例3: run
def run(filename):
global basename
global frames
global knobs
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
commands = list(commands)
cur = 0
for x in commands:
commands[cur] = list(commands[cur])
cur += 1
animated = first_pass(commands)
second_pass(commands, frames)
print frames
print knobs
print "basename " + basename
# runCommands(commands, 30, animated)
for frameNum in range(frames):
runCommands(commands, frameNum, animated)
示例4: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident(tmp)
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
stack = [ tmp ]
screen = new_screen()
for command in commands:
#print command
matrix = []
if command[0] == "push":
stack.append(copy.deepcopy(stack[-1]))
elif command[0] == "pop":
stack.pop()
elif command[0] == "line":
add_edge(matrix, command[1],command[2],command[3],command[4], command[5],command[6])
draw_lines( matrix, screen, color )
matrix=[];
elif command[0] in ["sphere","box","torus"]:
if command[0] == "sphere":
add_sphere(matrix,command[1],command[2],command[3],command[4],5)
elif command[0] == "box":
add_box(matrix, command[1],command[2],command[3],command[4], command[5],command[6])
else:
add_torus(matrix, command[1],command[2],command[3],command[4], command[5],5)
matrix_mult(stack[-1],matrix)
draw_polygons( matrix, screen, color )
matrix=[];
elif command[0] in ["move","scale","rotate"]:
if command[0] == "move":
t= make_translate(command[1],command[2],command[3])
elif command[0] == "scale":
t = make_scale(command[1],command[2],command[3])
else:
r = command[2]*(math.pi/180.0)
if command[1] == "x":
t = make_rotX(r)
elif command[1] == "y":
t = make_rotY(r)
elif command[1] == "z":
t = make_rotZ(r)
matrix_mult(stack[-1],t)
stack[-1]=t
elif command[0] == "display":
display( screen )
elif command[0] == "save":
save_extension( screen, command[1] )
示例5: run
def run(filename):
r = mdl.parseFile(filename)
if r:
(commands, symbols) = r
scan(commands)
else:
print "parsing failed"
return
示例6: run
def run(filename):
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
for command in commands:
cmd = command[0]
if cmd == "push":
stack.append(copy.deepcopy(stack[len(stack)-1]))
if cmd == "pop":
stack.pop()
if cmd == "move":
mult(make_translate(command[1], command[2], command[3]))
if cmd == "rotate":
t = command[2]*math.pi/180
axis = command[1]
if axis == 'x':
mult(make_rotX(t))
if axis == 'y':
mult(make_rotY(t))
if axis == 'z':
mult(make_rotZ(t))
if cmd == "scale":
mult(make_scale(command[1], command[2], command[3]))
if cmd in ["box", "sphere", "torus"]:
polygons = []
if cmd == "box":
add_box(polygons, command[1],command[2],command[3],command[4],command[5],command[6])
if cmd == "sphere":
add_sphere(polygons, command[1],command[2],command[3],command[4],5)
if cmd == "torus":
add_torus(polygons, command[1],command[2],command[3],command[4],command[5],5)
matrix_mult(stack[len(stack)-1], polygons)
draw_polygons(polygons, screen, color)
if cmd == "line":
points = []
add_edge(points, command[1],command[2],command[3],command[4],command[5],command[6])
matrix_mult(stack[len(stack)-1], points)
draw_lines(polygons, screen, color)
if cmd == "save":
save_extension(screen, cmd[1])
if cmd == "display":
display(screen)
示例7: run
def run(filename):
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
first_pass(commands)
示例8: run
def run(filename):
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
commands, symbols = p
if is_animated(commands):
frames = num_frames(commands)
#print symbols
# Set knob values for each frame
knobs = make_knobs(commands, frames)
#print jsonfmt(knobs, sort_keys=True, indent=4)
basename = get_basename(commands)
# Construct format string using format string
fmt_string = "%s-%%0%dd.gif" % (basename, int(1 + max(log10(frames), 0)) )
#print fmt_string
screen = new_screen()
for i in range(frames):
print "Drawing frame %d of %d ..." % (i, frames - 1)
draw_frame(commands, symbols, screen, knobs, i)
save_extension(screen, fmt_string % (i))
print '''
Done making your animation.
To show it, run the following ImageMagick terminal commands:
$ convert %s-*.gif %s.gif && animate -loop 0 %s.gif
- or -
$ animate -loop 0 %s-*.gif
Have a nice day!
''' % (basename, basename, basename, basename)
else:
draw_frame(commands, symbols)
else:
print "Parsing failed."
return
示例9: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
stack = [ tmp ]
screen = new_screen()
for command in commands:
print command
示例10: run
def run(filename):
"""
This function runs an mdl script
"""
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
num_frames,basename = first_pass(commands)
frames = second_pass(commands,num_frames)
if num_frames > 1 and not os.path.exists("anim"):
os.makedirs("anim")
for frame,i in zip(frames,range(len(frames))):
print i,frame
screen = run_frame(commands,frame)
if num_frames > 1:
save_ppm(screen, "anim/"+basename+("%03d"%i)+".ppm")
示例11: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
(name, num_frames) = first_pass( commands )
knobs = second_pass( commands, num_frames )
for f in range( num_frames ):
stack = [ tmp ]
screen = new_screen()
z_buffer = new_screen(XRES, YRES, [None])
for command in commands:
if command[0] == "pop":
stack.pop()
if not stack:
stack = [ tmp ]
if command[0] == "push":
stack.append( stack[-1][:] )
if command[0] == "save":
save_extension(screen, command[1])
if command[0] == "display":
display(screen)
if command[0] == "sphere":
m = []
add_sphere(m, command[1], command[2], command[3], command[4], 5)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, z_buffer, color )
if command[0] == "torus":
m = []
add_torus(m, command[1], command[2], command[3], command[4], command[5], 5)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, z_buffer,color )
if command[0] == "box":
m = []
add_box(m, *command[1:])
matrix_mult(stack[-1], m)
draw_polygons( m, screen, z_buffer, color )
if command[0] == "line":
m = []
add_edge(m, *command[1:])
matrix_mult(stack[-1], m)
draw_lines( m, screen, z_buffer, color )
if command[0] == "bezier":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'bezier')
matrix_mult(stack[-1], m)
draw_lines( m, screen, z_buffer, color )
if command[0] == "hermite":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'hermite')
matrix_mult(stack[-1], m)
draw_lines( m, screen, z_buffer, color )
if command[0] == "circle":
m = []
add_circle(m, command[1], command[2], command[3], command[4], .05)
matrix_mult(stack[-1], m)
draw_lines( m, screen, z_buffer, color )
if command[0] == "move":
xval = command[1]
yval = command[2]
zval = command[3]
if command[4]:
knob = knobs[f][command[4]]
xval*= knob
yval*= knob
zval*= knob
t = make_translate(xval, yval, zval)
matrix_mult( stack[-1], t )
stack[-1] = t
if command[0] == "scale":
xval = command[1]
yval = command[2]
#.........这里部分代码省略.........
示例12: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident(tmp)
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
stack = [tmp]
screen = new_screen()
points = []
for command in commands:
print command
if command[0] in ARG_COMMANDS:
if command[0] == "line":
add_edge(points, command[1], command[2], command[3], command[4], command[5], command[6])
matrix_mult(stack[-1], points)
draw_lines(points, screen, color)
points = []
elif command[0] == "scale":
t = make_scale(command[1], command[2], command[3])
matrix_mult(stack[-1], t)
stack[-1] = t
elif command[0] == "move":
t = make_translate(command[1], command[2], command[3])
matrix_mult(stack[-1], t)
stack[-1] = t
elif command[0] == "rotate":
if command[1] == "x":
t = make_rotX(command[2] * math.pi / 180)
elif command[1] == "y":
t = make_rotY(command[2] * math.pi / 180)
elif command[1] == "z":
t = make_rotZ(command[2] * math.pi / 180)
matrix_mult(stack[-1], t)
stack[-1] = t
elif command[0] == "circle":
add_cricle(points, command[1], command[2], 0, command[3], 0.01)
matrix_mult(stack[-1], points)
draw_lines(points, screen, color)
points = []
elif command[0] == "bezier":
add_curve(
points,
command[1],
command[2],
command[3],
command[4],
command[5],
command[6],
command[7],
command[8],
0.01,
"bezier",
)
matrix_mult(stack[-1], points)
draw_lines(points, screen, color)
points = []
elif command[0] == "hermite":
add_curve(
points,
command[1],
command[2],
command[3],
command[4],
command[5],
command[6],
command[7],
command[8],
0.01,
"hermite",
)
matrix_mult(stack[-1], points)
draw_lines(points, screen, color)
points = []
elif command[0] == "sphere":
add_sphere(points, command[1], command[2], command[3], command[4], 5)
matrix_mult(stack[-1], points)
draw_polygons(points, screen, color)
points = []
elif command[0] == "torus":
add_torus(points, command[1], command[2], 0, command[3], command[4], 5)
matrix_mult(stack[-1], points)
draw_polygons(points, screen, color)
points = []
elif command[0] == "box":
add_box(points, command[1], command[2], command[3], command[4], command[5], command[6])
matrix_mult(stack[-1], points)
draw_polygons(points, screen, color)
points = []
# elif command[0] == "ident":
#.........这里部分代码省略.........
示例13: make_scale
if command[0] == "scale":
xval = command[1]
yval = command[2]
zval = command[3]
t = make_scale(xval, yval, zval)
matrix_mult( stack[-1], t )
stack[-1] = t
if command[0] == "rotate":
angle = command[2] * (math.pi / 180)
if command[1] == 'x':
t = make_rotX( angle )
elif command[1] == 'y':
t = make_rotY( angle )
elif command[1] == 'z':
t = make_rotZ( angle )
matrix_mult( stack[-1], t )
stack[-1] = t
if __name__ == "__main__":
p = mdl.parseFile(raw_input(">"))
if p:
(commands, symbols) = p
first_pass(commands)
print second_pass(commands)
示例14: run
def run(filename):
global basename
global num_frames
global varies
global has_anim
global constantd
global ls
global a
"""
This function runs an mdl script
"""
color = [100, 100, 255]
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
stack = [new_matrix()]
ident(stack[-1])
screen = new_screen()
zbuff = [[-9223372036854775807 for x in range(500)] for x in range(500)]
first_pass(commands)
print num_frames
print basename
second_pass(commands,num_frames)
print "STACK: " + str(stack)
for frame in range(0,num_frames):
for command in commands:
if command[0] == "pop":
stack.pop()
if not stack:
stack = [ tmp ]
if command[0] == "push":
stack.append(stack[-1][:] )
if command[0] == "save":
save_extension(screen, command[1])
if command[0] == "display":
display(screen)
if command[0] == "sphere":
m = []
#constan = constantd[command[1]]
add_sphere(m, command[1], command[2], command[3], command[4], 5)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color,zbuff,[.3,.3,.3],[.3,.3,.3],[.8,.8,.8],[255,255,255],[[[0,0,255],[command[2]-10, command[3]-10, command[4]-100]]] )
if command[0] == "torus":
m = []
add_torus(m, command[1], command[2], command[3], command[4], command[5], 15)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color,zbuff,[.5,.5,.5],[.4,.4,.4],[.1,.1,.1],[0,0,0],[[[150,0,50],[command[1]-10, command[2]-10, command[3]-100]]] )
if command[0] == "box":
m = []
add_box(m, *command[1:])
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color,zbuff,[.5,.5,.5],[.4,.4,.4],[.1,.1,.1],[0,0,0],[[[0,0,255],[command[2]-10, command[3]-10, command[4]-100]]] )
if command[0] == "line":
m = []
add_edge(m, *command[1:])
matrix_mult(stack[-1], m)
draw_lines( m, screen, color,zbuff )
if command[0] == "bezier":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'bezier')
matrix_mult(stack[-1], m)
draw_lines( m, screen, color,zbuff )
if command[0] == "hermite":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'hermite')
matrix_mult(stack[-1], m)
draw_lines( m, screen, color,zbuff )
if command[0] == "circle":
m = []
add_circle(m, command[1], command[2], command[3], command[4], .05)
matrix_mult(stack[-1], m)
draw_lines( m, screen, color )
if command[0] in ["move","scale","rotate"]:
if command[0] == "move":
xval = command[1]
yval = command[2]
zval = command[3]
#.........这里部分代码省略.........
示例15: run
def run(filename):
"""
This function runs an mdl script
"""
color = [255, 255, 255]
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
screen = new_screen()
first_pass(commands)
second_pass(commands, nframes)
print nframes
try:
os.mkdir(basename)
except:
pass
for j in range(nframes):
stack = [ tmp ]
for command in commands:
if command[0] == "pop":
stack.pop()
if not stack:
stack = [ tmp ]
if command[0] == "ambient":
color[0] = command[1]
color[1] = command[2]
color[2] = command[3]
if command[0] == "push":
stack.append( stack[-1][:] )
if command[0] == "save":
save_extension(screen, command[1])
if command[0] == "display":
display(screen)
if command[0] == "sphere":
m = []
add_sphere(m, command[1], command[2], command[3], command[4], 5)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color )
if command[0] == "torus":
m = []
add_torus(m, command[1], command[2], command[3], command[4], command[5], 5)
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color )
if command[0] == "box":
m = []
add_box(m, *command[1:])
matrix_mult(stack[-1], m)
draw_polygons( m, screen, color )
if command[0] == "line":
m = []
add_edge(m, *command[1:])
matrix_mult(stack[-1], m)
draw_lines( m, screen, color )
if command[0] == "bezier":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'bezier')
matrix_mult(stack[-1], m)
draw_lines( m, screen, color )
if command[0] == "hermite":
m = []
add_curve(m, command[1], command[2], command[3], command[4], command[5], command[6], command[7], command[8], .05, 'hermite')
matrix_mult(stack[-1], m)
draw_lines( m, screen, color )
if command[0] == "circle":
m = []
add_circle(m, command[1], command[2], command[3], command[4], .05)
matrix_mult(stack[-1], m)
draw_lines( m, screen, color )
if command[0] == "move":
if command[-1] == "mover":
xval = command[1]*knob[j]["mover"]
yval = command[2]*knob[j]["mover"]
zval = command[3]*knob[j]["mover"]
else:
xval = command[1]
yval = command[2]
zval = command[3]
t = make_translate(xval, yval, zval)
#.........这里部分代码省略.........