Raw image sequence assignment

From XPUB & Lens-Based wiki
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 # 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")

m0GBwAz.gif

with Michael...