User:Lucia Dossin/Protyping/Assignment 3/Image Sequence

From XPUB & Lens-Based wiki
< User:Lucia Dossin‎ | Protyping‎ | Assignment 3
Revision as of 22:59, 6 November 2013 by Lucia Dossin (talk | contribs) (Created page with "Modifications on the code uploaded to the Assignment page: 1.Instead of making the line move each 10 pixels, I used an ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Modifications on the code uploaded to the Assignment page:

1.Instead of making the line move each 10 pixels, I used an interval of 320/25, so that the line would reach the right margin of the file at the last frame (well, I just saw it actually doesn't).

2.Added colors to the portion of the file on the left side of the line. In the old version of the code, each line would contain N black pixels, 1 white pixel and Z more black pixels. In the new version, N random color pixels, 1 white pixel, Z black pixels. This has increased both the render time and and file size tremendously (from 18Kb to 1.2Mb).

The code:

import struct, sys, random
 
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("colors/frame_%02d.tga" % frame, "wb")
    out.write(header)
 
    for y in xrange(height):
        for x in xrange(width):
            if ( x == frame*(320/25)):
                r = 255
                g = 255
                b = 255
                a = 255
            else:
                if (x < frame *(320/25)):
                    r = random.randint(0, 255)
                    g = random.randint(0, 255)
                    b = random.randint(0, 255)
                    a = 255
                else:
                    r = 0
                    g = 0
                    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))
 
    out.close()

Colors lucia.gif