User:Lidia.Pereira/PNM/Raw: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import struct, array
import struct, array
import random
   
   
width = 320
width = 320
Line 69: Line 68:
</syntaxhighlight>
</syntaxhighlight>
[[File:output2.png]]
[[File:output2.png]]
<syntaxhighlight lang="python">
import struct, array
width = 320
height = 240
filename="output3.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 = ''
attempt = height/2
largeColumns = (width/5) - 25
smallColumns = 15
smallerColumns = 10
for y in xrange(height):
    for x in xrange(5):
        for x in xrange(largeColumns):
            r, g, b = 0, 0, 0
            if y <= attempt:
                r = 55
                g = 255
                b = 44
            else:
                r = 155
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)
        for x in xrange(smallColumns):                                                                                                                                                         
            r, g, b = 0, 0, 0
            if y < 90:
                g = 155
            if y > 90 and y < 200:
                g = 4
            else:
                g = 90
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)
        for x in xrange(smallerColumns):                                                                                                                                                         
            r, g, b = 0, 0, 0
            if y < 55:
                b = 44
            if y > 55 and y < 195:
                b = 244
            else:
                b = 77
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)
   
datafile.write(data)
datafile.close()
</syntaxhighlight>
[[File:Output3.png]]

Latest revision as of 12:05, 14 October 2013

import struct, array
 
width = 320
height = 240
 
filename="output2.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 = ''
attempt = height/2

for y in xrange(height):
    for x in xrange(width/2):
        r, g, b = 0, 0, 0
        if y <= attempt:
            r = 255
        if y > 15 and y < 30:
            b = 144
        if y > attempt and y < 177:
            r = 155
        if y > 177:
            r = 44
        data += struct.pack('B', b)
        data += struct.pack('B', g)
        data += struct.pack('B', r)
    for x in xrange(width/4):
        r, g, b = 0, 0, 0
        if y <= attempt:
            g = 155
        if y > 70 and y < 90:
            r = 144
        if y > attempt/2 and y < 91:
            b = 155
        if x > width/4 and x < width - width/4:
            b = 255
        else:
            b = 77
        data += struct.pack('B', b)
        data += struct.pack('B', g)
        data += struct.pack('B', r)
    for x in xrange(width/4):
        r, g, b = 0, 0, 0
        if y <= attempt:
            b = 155
        if y > 99 and y < 191:
            g = 144
        if y > attempt and y < 190:
            r = 155
        if x > width - width/4:
            b = 255
        else:
            b = 55
        data += struct.pack('B', b)
        data += struct.pack('B', g)
        data += struct.pack('B', r)



datafile.write(data)
datafile.close()

Output2.png

import struct, array
 
width = 320
height = 240
 
filename="output3.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 = ''
attempt = height/2
largeColumns = (width/5) - 25
smallColumns = 15
smallerColumns = 10


for y in xrange(height):
    for x in xrange(5):
        for x in xrange(largeColumns):
            r, g, b = 0, 0, 0
            if y <= attempt:
                r = 55
                g = 255
                b = 44
            else:
                r = 155
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)

        for x in xrange(smallColumns):                                                                                                                                                           
            r, g, b = 0, 0, 0
            if y < 90:
                g = 155
            if y > 90 and y < 200:
                g = 4 
            else:
                g = 90
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)

        for x in xrange(smallerColumns):                                                                                                                                                           
            r, g, b = 0, 0, 0
            if y < 55:
                b = 44
            if y > 55 and y < 195:
                b = 244 
            else:
                b = 77
            data += struct.pack('B', b)
            data += struct.pack('B', g)
            data += struct.pack('B', r)

    

datafile.write(data)
datafile.close()

Output3.png