本文整理汇总了Python中mdl.parseFile函数的典型用法代码示例。如果您正苦于以下问题:Python parseFile函数的具体用法?Python parseFile怎么用?Python parseFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseFile函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
开发者ID:Masa13,项目名称:graphics_final,代码行数:32,代码来源:script.py
示例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]
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:25,代码来源:script2.py
示例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)
开发者ID:jijiglobe,项目名称:Graphics-Engine,代码行数:32,代码来源:script.py
示例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] )
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:57,代码来源:script.py
示例5: run
def run(filename):
r = mdl.parseFile(filename)
if r:
(commands, symbols) = r
scan(commands)
else:
print "parsing failed"
return
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:9,代码来源:script.py
示例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)
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:51,代码来源:script.py
示例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)
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:14,代码来源:script.py
示例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
开发者ID:aidan-fitz,项目名称:graphics16,代码行数:49,代码来源:interpreter.py
示例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
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:21,代码来源:script.py
示例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")
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:23,代码来源:script.py
示例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]
#.........这里部分代码省略.........
开发者ID:sammiWL,项目名称:supreme-spork,代码行数:101,代码来源:script.py
示例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":
#.........这里部分代码省略.........
开发者ID:jerrylei98,项目名称:graphics_homework,代码行数:101,代码来源:script.py
示例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)
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:30,代码来源:script.py
示例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]
#.........这里部分代码省略.........
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:101,代码来源:script.py
示例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)
#.........这里部分代码省略.........
开发者ID:kagers,项目名称:g-animation,代码行数:101,代码来源:script.py
示例16: run
def run(filename):
color = [255, 255, 255]
tmp = new_matrix()
ident(tmp)
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
animation_values = first_pass(commands)
isAnimated = True
frame_values = []
if animation_values[0] is None:
animation_values[0] = 1
isAnimated = False
else:
frame_values = second_pass(commands, animation_values[0])
for i in range(animation_values[0]):
screen = new_screen()
z_buffer = new_screen(XRES, YRES, [None])
stack = [tmp]
print "Frame %04d" % i
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_flat_polygons(m, screen, z_buffer)
#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_flat_polygons(m, screen, z_buffer)
#draw_polygons( m, screen, z_buffer, color )
if command[0] == "box":
m = []
add_box(m, *command[1:])
matrix_mult(stack[-1], m)
draw_flat_polygons(m, screen, z_buffer)
#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, color )
if command[0] in ["move", "scale", "rotate"]:
factor = 1
if command[-1] and len(frame_values) > 0:
factor = frame_values[i][command[-1]]
t = new_matrix()
if command[0] == "move":
xval = command[1] * factor
yval = command[2] * factor
zval = command[3] * factor
t = make_translate(xval, yval, zval)
if command[0] == "scale":
xval = command[1] * factor
yval = command[2] * factor
zval = command[3] * factor
t = make_scale(xval, yval, zval)
if command[0] == "rotate":
angle = command[2] * (math.pi / 180) * factor
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 isAnimated:
save_extension(screen, "anim/" + animation_values[1] + "%04d.png" % i)
开发者ID:dillzhang,项目名称:graphics_final,代码行数:100,代码来源:script.py
示例17: run
def run(filename):
"""
This function runs an mdl script
"""
tmp = new_matrix()
ident( tmp )
p = mdl.parseFile(filename)
if p:
(commands, symbols) = p
else:
print "Parsing failed."
return
num_frames = 1
animation_frames = []
basename = "img%03d"
color = [0, 0, 0]
ambient_light = [10, 10, 10]
diffuse_light = [[[100, 100, 100],[-1,0,0]]]
spec_light = [[[120, 120, 120],[-1,-1,0]]]
#first pass
for command in commands:
operator = command[0]
if operator == "frames":
num_frames = command[1]
elif operator == "basename":
basename = command[1] + "%03d"
if basename == "img%03d":
print "No animation basename specified, using 'img*'"
#second pass
for command in commands:
operator = command[0]
for i in range(num_frames):
animation_frames.append({})
if operator == "vary":
if num_frames <= 1:
print "Frames not set, but vary used"
sys.exit()
if command[1] not in animation_frames[0]:
for i in range(num_frames):
animation_frames[i][command[1]] = 0
start = command[2]
end = command[3]
startVal = command[4]
endVal = command[5]
for i in range(start, end + 1):
animation_frames[i][command[1]] = startVal + 1. * (endVal - startVal) / (end - start) * (i - start)
#third pass
for i in range(num_frames):
stack = [ tmp ]
screen = new_screen()
zbuffer = new_zbuffer()
for command in commands:
#print command
operator = command[0]
if operator == "push":
stack.append(copy.deepcopy(stack[-1])) #deepcopy required to copy an independent matrix
elif operator == "pop":
stack.pop()
elif operator == "move":
v = 1
if command[4] != None:
v = animation_frames[i][command[4]]
M = make_translate(command[1] * v, command[2] * v, command[3] * v)
matrix_mult(stack[-1], M)
stack[-1] = M
elif operator == "rotate":
v = 1
if command[3] != None:
v = animation_frames[i][command[3]]
if command[1] == "x":
M = make_rotX(command[2] * v)
elif command[1] == "y":
M = make_rotY(command[2] * v)
elif command[1] == "z":
M = make_rotZ(command[2] * v)
matrix_mult(stack[-1], M)
stack[-1] = M
elif operator == "scale":
v = 1
if command[4] != None:
v = animation_frames[i][command[4]]
M = make_scale(command[1] * v, command[2] * v, command[3] * v)
matrix_mult(stack[-1], M)
stack[-1] = M
elif operator == "box":
points = []
add_prism(points, command[1], command[2], command[3], command[4], command[5], command[6])
matrix_mult(stack[-1], points)
draw_polygons(points, screen, color, zbuffer,
ambient_light, diffuse_light, spec_light)
elif operator == "sphere":
points = []
add_sphere(points, command[1], command[2], command[3], command[4])
#.........这里部分代码省略.........
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:101,代码来源:script.py
示例18: run
def run(filename):
"""
This function runs an mdl script
"""
zbuff = z_buffer()
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()
counter = 0
first_pass(commands)
if NUM_FRAMES == 1:
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":
print command[0]
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], 2)
matrix_mult(stack[-1], m)
counter = (counter + 1) % 3
color = coors[counter]
draw_polygons(m, screen, color, zbuff)
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, zbuff)
if command[0] == "box":
m = []
counter = (counter + 1) % 3
color = coors[counter]
add_box(m, *command[1:])
matrix_mult(stack[-1], m)
draw_polygons(m, screen, color, zbuff)
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],
0.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],
0.05,
"hermite",
)
matrix_mult(stack[-1], m)
#.........这里部分代码省略.........
开发者ID:koprty,项目名称:graphics-hw-spring_2015,代码行数:101,代码来源:script.py
注:本文中的mdl.parseFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论