Raw image: Difference between revisions
(Created page with "<source lang="python"> import struct, array width = 640 height = 480 filename="output.tga" datafile = open(filename, "wb") # TGA format: http://gpwiki.org/index.php/TGA # Of...") |
No edit summary |
||
Line 2: | Line 2: | ||
import struct, array | import struct, array | ||
width = | width = 320 | ||
height = | height = 240 | ||
filename="output.tga" | filename="output.tga" | ||
Line 18: | Line 18: | ||
r, g, b = 0, 0, 0 | r, g, b = 0, 0, 0 | ||
if y < | if y < 32: | ||
r = 255 | r = 255 | ||
if x > | if x > 64 and x < 256: | ||
g = 255 | g = 255 | ||
if y > | if y > 120: | ||
r = 128 | r = 128 | ||
Revision as of 15:29, 8 October 2013
import struct, array
width = 320
height = 240
filename="output.tga"
datafile = open(filename, "wb")
# TGA format: http://gpwiki.org/index.php/TGA
# Offset, ColorType, ImageType, PaletteStart, PaletteLen, PalBits, XOrigin, YOrigin, Width, Height, BPP, Orientation
header = struct.pack("<BBBHHBHHHHBB", 0, 0, 2, 0, 0, 8, 0, 0, width, height, 24, 1 << 5)
datafile.write(header)
data = ''
for y in xrange(height):
for x in xrange(width):
r, g, b = 0, 0, 0
if y < 32:
r = 255
if x > 64 and x < 256:
g = 255
if y > 120:
r = 128
data += struct.pack('B', b)
data += struct.pack('B', g)
data += struct.pack('B', r)
datafile.write(data)
datafile.close()