User:Luisa Moura/prototyping/python: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
(Blanked the page)
 
Line 1: Line 1:
[[File:Chessboard.gif|none]]


<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 xrange(totalframes):
    out = open("frame%04d.tga" % frame, "wb")
    out.write(header)
    for y in xrange(height):
        for x in xrange(width):
            r = ((float(frame)/totalframes))*255
            g = 0
            b = 0
            a = 150
            if y <= 80:
                b = 20
                g = 50
            if y >= 80 and y <=160:
                r = 200
                b = 220
           
            if y >= 160:
                b = 150
                g = 75
            if x > 80 and x < 160:
                g = r
            if x > 160 and x < 240:
                g = 50   
            if x > 240:
                g = 200 
            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()
</source>
[[Image:color.gif]]
<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 xrange(totalframes):
    out = open("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 = 0
            b = 0
            a = 255
            if x > 80 and x < 160:
                g = r
            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()
</source>
[[File:Raw image.jpg|thumbnail]]
<source lang="python">
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import struct
f = open("image.data", 'w')
data = ''
for x in range(10000):
        data += struct.pack('B', 255)
        data += struct.pack('B', 0)
        data += struct.pack('B', 0)
for x in range(20000):
        data += struct.pack('B', 0)
        data += struct.pack('B', 75)
        data += struct.pack('B', 0)
for x in range(2000):
        data += struct.pack('B', 50)
        data += struct.pack('B', 50)
        data += struct.pack('B', 25)
for x in range(50000):
        data += struct.pack('B', 255)
        data += struct.pack('B', 0)
        data += struct.pack('B', 0)
f.write(data)
f.close()
</source>
<source lang="python">
[[File:image raw 9.jpg|thumbnail]]
import struct
import random
f = open("image.data", 'w')
data = ''
for x in range(random.randint(0,10000)):
    if x % 2:
        data += struct.pack('B', 255)
        data += struct.pack('B', 0)
        data += struct.pack('B', 0)
    else:
        data += struct.pack('B', 0)
        data += struct.pack('B', 255)
        data += struct.pack('B', 0)
for x in range(random.randint(0,10000)):
    if x % 2:
        data += struct.pack('B', 50)
        data += struct.pack('B', 20)
        data += struct.pack('B', 0)
    else:
        data += struct.pack('B', 0)
        data += struct.pack('B', 75)
        data += struct.pack('B', 0)
f.write(data)
f.close()
</source>
==experiments with Henk-Jelle==
[[File:Raw image 6.jpg|thumbnail]]
<source lang="python">
import struct
import random
f = open("image.data", 'w')
data = ''
for x in range(100000):
varR = random.randint(0,255)
varG = random.randint(0,255)
varB = random.randint(0,255)
data += struct.pack('B', varR)
data += struct.pack('B', varG)
        data += struct.pack('B', varB)
f.write(data)
f.close()

Latest revision as of 13:33, 9 April 2014