Blockland Forums > General Discussion

Badspot's Dev Server

Pages: << < (50/64) > >>

otto-san:


--- Quote from: Blocki on May 20, 2012, 01:12:48 PM ---No.

--- End quote ---
I'm afraid so.

Port:


--- Quote from: otto-san on May 20, 2012, 01:12:12 PM ---Black magic.

You require fifty-seven pythons and two pieces of paper.

--- End quote ---

only 51 pythons


--- Code: ---# Import modules.
print 'Initializing.'
from math import floor
import Image

# Initialize images.
print 'Loading images.'
img1 = Image.open('img1.png')
img2 = Image.open('img2.png')

maxx = max(img1.size[0], img2.size[0])
maxy = max(img1.size[1], img2.size[1])
imgf = Image.new('RGBA', (maxx, maxy), (0, 0, 0, 0))

ima1 = img1.load()
ima2 = img2.load()
imaf = imgf.load()

# Subsitute color shape.
def replace_color(alp, mod):
    if type(alp) is tuple:
        if len(alp) == 4:
            alp = alp[3]
        else:
            alp = 255

    return ((255, 255, 255, alp), (175, 198, 219, alp))[mod]

# Perform operation.
print 'Performing operation.'
for i in range(maxx * maxy):
    y = floor(i / maxx)
    x = i - (y * maxx)
    
    try: a = ima1[x, y]
    except IndexError: a = (0, 0, 0, 0)

    try: b = ima2[x, y]
    except IndexError: b = (0, 0, 0, 0)

    if (x + y) % 2 == 0:
    # if True:
        # imaf[x, y] = a
        imaf[x, y] = replace_color(a, 0)
    else:
        # imaf[x, y] = b
        imaf[x, y] = replace_color(b, 1)

# Save output.
print 'Exporting.'
imgf.save('imgf.png')

--- End code ---

essentially only 33 pythons because of comments and whitespace

Blocki:


--- Quote from: Port on May 20, 2012, 01:16:02 PM ---only 51 pythons


--- Code: ---# Import modules.
print 'Initializing.'
from math import floor
import Image

# Initialize images.
print 'Loading images.'
img1 = Image.open('img1.png')
img2 = Image.open('img2.png')

maxx = max(img1.size[0], img2.size[0])
maxy = max(img1.size[1], img2.size[1])
imgf = Image.new('RGBA', (maxx, maxy), (0, 0, 0, 0))

ima1 = img1.load()
ima2 = img2.load()
imaf = imgf.load()

# Subsitute color shape.
def replace_color(alp, mod):
    if type(alp) is tuple:
        if len(alp) == 4:
            alp = alp[3]
        else:
            alp = 255

    return ((255, 255, 255, alp), (175, 198, 219, alp))[mod]

# Perform operation.
print 'Performing operation.'
for i in range(maxx * maxy):
    y = floor(i / maxx)
    x = i - (y * maxx)
   
    try: a = ima1[x, y]
    except IndexError: a = (0, 0, 0, 0)

    try: b = ima2[x, y]
    except IndexError: b = (0, 0, 0, 0)

    if (x + y) % 2 == 0:
    # if True:
        # imaf[x, y] = a
        imaf[x, y] = replace_color(a, 0)
    else:
        # imaf[x, y] = b
        imaf[x, y] = replace_color(b, 1)

# Save output.
print 'Exporting.'
imgf.save('imgf.png')

--- End code ---

--- End quote ---
That has nothing to do with the image

Port:


--- Quote from: Blocki on May 20, 2012, 01:17:51 PM ---That has nothing to do with the image

--- End quote ---

yes it does

place images named img1.png and img2.png in folder with that script
run script
suddenly, new image named imgf.png is in folder which displays those two depending on the background

Blocki:


--- Quote from: Port on May 20, 2012, 01:18:48 PM ---yes it does

place images named img1.png and img2.png in folder with that script
run script
suddenly, new image named imgf.png is in folder which displays those two depending on the background

--- End quote ---
What file suffix?

Pages: << < (50/64) > >>

Go to full version