Raw image sequence assignment: Difference between revisions
(Created page with " # rawimagesequence.py import struct, sys width = 320 height = 240 header = struct.pack("<BBBHHBHHHHBB",0,0,2,0,0,8,0,0,width,height,32,1<<5) totalframes = 25 def map(x, st...") |
No edit summary |
||
Line 1: | Line 1: | ||
<source lang="python"> | |||
# rawimagesequence.py | # rawimagesequence.py | ||
import struct, sys | import struct, sys | ||
Line 34: | Line 36: | ||
import os | import os | ||
os.system("convert frame* nik.gif") | os.system("convert frame* nik.gif") | ||
</source> |
Revision as of 18:52, 18 November 2013
# rawimagesequence.py
import struct, sys
width = 320
height = 240
header = struct.pack("<BBBHHBHHHHBB",0,0,2,0,0,8,0,0,width,height,32,1<<5)
totalframes = 25
def map(x, startend, newstartnewend):
start, end = startend
newstart, newend = newstartnewend
p = (float(x) - start) / (end - start)
return newstart + (p * (newend-newstart))
for frame in xrange(totalframes):
out = open("frame%02d.tga" % frame, "wb")
out.write(header)
for y in xrange(height):
for x in xrange(width):
r = map(frame, (0, totalframes), (255, 0))
g = map(frame, (0, totalframes), (0, 255))
b = 0
a = 255
out.write(struct.pack('B', b))
out.write(struct.pack('B', g))
out.write(struct.pack('B', r))
out.write(struct.pack('B', a))
print r
out.close()
import os
os.system("convert frame* nik.gif")