Midterm Exam 2 Review Spring 2006: Some Movie Code
Is the code making sure that all the frame numbers are at least three digits long? Is it needed so that the frames will run in order when put into a movie maker or whatever?
Do you set the directory in the black area? and if so, what would be an example of what I would set it to?
| The directory is one of the input parameters that you give it. An example of running the function would be... writeFrame(frame, r"C:\Documents and Settings\Charlie\cs1315\HW3\frames", pic). 'frame' is a variable defined elsewhere is your program, YOU give it the directory of where to write the frames to, and the last input is the picture that you want to write. -poof #10 |
def writeFrame(num, directory, framepict):
framenum=str(num)
if num < 10:
writePictureTo(framepict, directory + "//frame00" + framenum + ".jpg")
elif num < 100:
writePictureTo(framepict, directory + "//frame0" + framenum + ".jpg")
else:
writePictureTo(framepict, directory + "//frame" + framenum + ".jpg")
is this the shortest way????
I think this is the shortest way:
num = str(frame)
if len(num) == 1:
num = '0' + num
writePictureTo(canvas, directory + '//frame' + num + '.jpg')
that wont work becuase you'll get frame01.jpg, frame10.jpg and frame100.jpg and they want frame001.jpg, frame010.jpg, and frame100.jpg
def writeFrame(num,directory,framepict):
framenum=str(num)
zeros=3-len(num)
writePictureTo(framepict, directory+"//frame"+zeros+framenum+".jpg")
I think this ought to work.
Link to this Page