Raw image sequence: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="python"> 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 for frame in x...")
 
No edit summary
Line 26: Line 26:
     out.close()
     out.close()
</source>
</source>
Using [[Imagemagick]] to convert this to an animated gif:

Revision as of 13:08, 5 November 2013

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
for frame in xrange(totalframes):
    out = open("out/frame%04d.tga" % frame, "wb")
    out.write(header)

    for y in xrange(height):
        for x in xrange(width):
            r = (1.0-(float(frame)/totalframes))*255
            g = r
            b = r
            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()

Using Imagemagick to convert this to an animated gif: