def color_map(color_list, keylist): # TODO: List shoudl be tuple ( str , inex ) total_len = keylist[-1] current_key = 0 color_map = [] for i, key in enumerate(keylist): color_map.append(bltColor(color_list[i])) try: interp_num = keylist[current_key+1] - keylist[current_key] - 1 bias_inc = 1.0 / (interp_num + 2) print "Bias_iv: {0}".format(bias_inc) bias = bias_inc for i in xrange(interp_num): colorA = bltColor(color_list[current_key]).getRGB() colorB = bltColor(color_list[current_key+1]).getRGB() a = max(min(int(colorA[3] + ((colorB[3] - colorA[3]) * bias)), 255), 0) r = max(min(int(colorA[0] + ((colorB[0] - colorA[0]) * bias)), 255), 0) g = max(min(int(colorA[1] + ((colorB[1] - colorA[1]) * bias)), 255), 0) b = max(min(int(colorA[2] + ((colorB[2] - colorA[2]) * bias)), 255), 0) color_map.append(bltColor(str(terminal.color_from_argb(a, r, g, b)))) #print "Bias_iv: {1} -> {0}".format(bias_inc, i) bias += bias_inc current_key+=1 print "InterOp: {0}".format(interp_num) index += interp_num except: pass print color_map return color_map
def __mul__(self, color2): if isinstance(color2, bltColor): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return bltColor(str(terminal.color_from_argb( a1, max(min(int(r1 * r2) // 255, 255), 0), max(min(int(g1 * g2) // 255, 255), 0), max(min(int(b1 * b2) // 255, 255), 0), ))) else: r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2, color2, color2, 1.0 return bltColor(str(terminal.color_from_argb( a1, max(min(int(r1 * r2), 255), 0), max(min(int(g1 * g2), 255), 0), max(min(int(b1 * b2), 255), 0), )))
def __sub__(self, color2): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return bltColor(str(terminal.color_from_argb( a1, max(r1 - r2, 0), max(g1 - g2, 0), max(b1 - b2, 0), )))
def __add__(self, color2): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return bltColor(str(terminal.color_from_argb( a1, min(r1 + r2, 255), min(g1 + g2, 255), min(b1 + b2, 255), )))
def blend(self, color2, bias=0.5, alpha=255 ): """Returns bltColor halfway between this color and color2""" colorA = self.getRGB() colorB = color2.getRGB() a = max(min(int(colorA[3] + ((colorB[3] - colorA[3]) * bias)), 255), 0) r = max(min(int(colorA[0] + ((colorB[0] - colorA[0]) * bias)), 255), 0) g = max(min(int(colorA[1] + ((colorB[1] - colorA[1]) * bias)), 255), 0) b = max(min(int(colorA[2] + ((colorB[2] - colorA[2]) * bias)), 255), 0) return bltColor(str(terminal.color_from_argb(a, r, g, b)))
def trans(self, alpha_value): """Returns a color with the alpha_value""" r, g, b, a= self.getRGB() #print alpha_value, r, g, b alpha_value = max(min(alpha_value, 255), 1) return bltColor(str(terminal.color_from_argb(alpha_value, r, g, b)))
terminal.open() terminal.set("window: size=80x25, cellsize=auto, title='Omni: menu';" "font: default;" "input: filter={keyboard}") terminal.composition(True) alphas = [16, 32, 64,80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255, 240, 224, 208, 192, 176, 160, 144, 128, 112, 96, 80, 64, 32] _alphas = cycle(alphas) terminal.color(terminal.color_from_argb(128, 255,30,30)) drawRect(5,5,10,10) color10 = bltColor('blue') terminal.color(terminal.color_from_argb(128, 30,30,255)) #terminal.color(color10.trans(255)) drawRect(10,10,10,10) l1 = (40, 12) l2 = (25, 5) l3 = (60, 18) l4 = (5, 5) l5 = (5, 18)