Raw image sequence assignment: Difference between revisions
No edit summary |
No edit summary |
||
Line 37: | Line 37: | ||
os.system("convert frame* nik.gif") | os.system("convert frame* nik.gif") | ||
</source> | </source> | ||
http://i.imgur.com/hkUE09l.gif |
Revision as of 18:55, 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")