Esempio n. 1
0
def lightmap(nm, cm, light, ambient):
    width, height = nm.size
    cwidth, cheight = cm.size

    if cwidth != width or cheight != height:
        print("Resolutions do not match.")
        exit()

    shaded = Image.new('RGBA', (width, height), color=(0, 0, 0, 0))

    prog = ProgressBar(height)

    print("\nLight Map:")

    for y in range(0, height):
        prog.show(y)
        for x in range(0, width):
            (cr, cg, cb, ca) = cm.getpixel((x, y))
            (r, g, b, a) = nm.getpixel((x, y))
            if a != 0:
                normal = vmath.Vector3(\
                    (r/255 - 0.5) * 2,
                    (g/255 - 0.5) * 2,
                    (b/255 - 0.5) * 2)
                angle = normal.angle(light, 'deg')
                illumination = 1 - (angle / 180)
                illumination = ambient + (1 - ambient) * illumination
                cr = int(illumination * cr)
                cg = int(illumination * cg)
                cb = int(illumination * cb)
                shaded.putpixel((x, y), (cr, cg, cb, ca))
    return shaded
Esempio n. 2
0
def colormap(hm, gradient, smoothness):
    width, height = hm.size

    img = Image.new('RGBA', (width, height), color=(0, 0, 0, 0))

    colorlist = []

    for g in range(len(gradient) - 1):
        (start, color) = gradient[g]
        (nextStart, nextColor) = gradient[g + 1]

        begin = start * smoothness
        end = (nextStart - start) * smoothness

        sublist = list(Color(color).range_to(Color(nextColor), end))
        colorlist += sublist

    prog = ProgressBar(height)

    print("\nColor Map:")

    for y in range(0, height):
        prog.show(y)
        for x in range(0, width):
            value = hm.getpixel((x, y))
            if value != -2147483648:
                setpixel(x, y, value, colorlist, img)
    return img
Esempio n. 3
0
def to_png(tif):
    width, height = tif.size

    img = Image.new('RGBA', (width, height), color=(0, 0, 0, 0))

    prog = ProgressBar(height - 1)

    print("\nTo PNG:")
    for y in range(0, height - 1):
        prog.show(y)
        for x in range(0, width - 1):
            value = tif.getpixel((x, y))
            setpixel(x, y, value, img)

    print("\n")
    return img
Esempio n. 4
0
def normalmap(hm, sobelscale):
    width, height = hm.size

    nm = Image.new('RGBA', (width, height), color=(0, 0, 0, 0))

    prog = ProgressBar(height)

    print("\nNormal Map:")

    for y in range(0, height):
        prog.show(y)
        for x in range(0, width):
            value = hm.getpixel((x, y))
            if value != -2147483648:
                normal = sobel(x, y, hm, sobelscale)
                color = (\
                    int(normal.x * 255),
                    int(normal.y * 255),
                    int(normal.z * 255), 255)
                nm.putpixel((x, y), color)

    return nm
Esempio n. 5
0
def projectmap(hm, scale):
    width, height = hm.size

    img = Image.new('I', (width, height), color=(-2147483648))

    rwidth, rheight = img.size
    R = rwidth / 6.1

    prog = ProgressBar(height)

    print("\nProjection Map:")

    for y in range(0, height):
        prog.show(y)
        for x in range(0, width):
            value = hm.getpixel((x, y))
            (lat, long) = cylToLatLon(x - width / 2, y, scale)
            (mapx, mapy) = robinson(lat, long, R)

            img.putpixel((int(mapx + rwidth / 2), int(mapy + rheight / 2)),
                         value)

    return img
Esempio n. 6
0
def heightmap(hm, scale):
    SCALER = scale

    width, height = hm.size

    img = Image.new('I', (width // SCALER, height // SCALER), color='red')

    prog = ProgressBar(height)

    print("\nHeight Map:")

    for y in range(0, height, SCALER):
        prog.show(y)
        for x in range(0, width // 2, SCALER):
            value = hm.getpixel((x, y))
            rightVal = hm.getpixel((x + width // 2, y))
            try:
                img.putpixel((x // SCALER * 2, y // SCALER), value)
                img.putpixel((x // SCALER * 2 + 1, y // SCALER), rightVal)
            except IndexError:
                pass

    return img
## Initialize Happiness dictionary
print "INITIALIZE DATA..."
CHILD_PREF = pd.read_csv('../input/child_wishlist_v2.csv',
                         header=None).drop(0, 1).values
GIFT_PREF = pd.read_csv('../input/gift_goodkids_v2.csv',
                        header=None).drop(0, 1).values
'''
==========================
Here we build a dictionary to compute single scores for all three types of children
'''
print "INITIALIZE GIFT HAPPINESS..."
GIFT_HAPPINESS = {}
pbar.setBar(N_GIFT_TYPE)
for g in range(N_GIFT_TYPE):
    pbar.show(g)
    GIFT_HAPPINESS[g] = defaultdict(lambda: -1. / (2 * N_GIFT_PREF))
    for i, c in enumerate(GIFT_PREF[g]):
        GIFT_HAPPINESS[g][c] = 1. * (N_GIFT_PREF - i) / N_GIFT_PREF

print "INITIALIZE CHILD HAPPINESS..."
CHILD_HAPPINESS = {}
pbar.setBar(N_CHILDREN)
for c in range(N_CHILDREN):
    pbar.show(c)
    CHILD_HAPPINESS[c] = defaultdict(lambda: -1. / (2 * N_CHILD_PREF))
    for i, g in enumerate(CHILD_PREF[c]):
        CHILD_HAPPINESS[c][g] = 1. * (N_CHILD_PREF - i) / N_CHILD_PREF
'''
==========================
Here we build a 2D hash_table to compute single scores for all the triplets
Esempio n. 8
0
neighbor = ""
lc = 0

# open input+output file
fh = open(sopts.inputfile, 'r')
fhout = open(sopts.outputfile, 'w')	# rewrite
fhout.write("timestamp,neighbor,capabilities,mrr_T,mrr_t,mrr_P,rate,throughput,ewma_prob,this_prob,this_succ,this_attempt,success,attempts\n")
linebuffer = []
headers = False
t0 = time()
print "getting length of file... ",
numlines = get_num_lines(sopts.inputfile)
if (numlines > -1):
	print "%d lines" % numlines
	progress = ProgressBar(50)
	progress.show(0)
else:
	print "failed"

while (main_loop):
	try:
		filepos = fh.tell()	# remember position before reading
		line = fh.readline()
		if ((not "\n" in line) and (line != '')):
			fh.seek(filepos)
		else:
			if (line != ''):
				lc += 1
				if (lc % 10000 == 0 and numlines > -1):
					duration = (time() - t0)
					t0 = time()