def test_rgb(self): from ansi.colour.rgb import rgb256 from ansi.colour.fx import reset msg = (rgb256(0xff, 0x80, 0x00), 'hello world', reset) self.assertEqual( ''.join(map(str, msg)), '\x1b[38;5;214mhello world\x1b[0m')
def _value_to_char(self, value): char = super()._value_to_char(value) colour = rgb256(*value) if self.background: colour.replace('38', '48', 1) # Modify the ANSI escape code to use bg instead of fg return colour + char + str(reset)
def convert_to_ansi_color(img): # get pixels pixels = img.load() string = "" for h in xrange(img.size[1]): for w in xrange(img.size[0]): rgb = pixels[w, h] string += rgb256(rgb[0], rgb[1], rgb[2]) + "▇ "+ reset.sequence string += "\n" return string
def img_to_colorcode(img): """ :param img: Image to process :type img: np.array, dim=(s1,s2,4) """ s1, s2 = img.shape[:2] col_mat = np.zeros((s1, s2)).astype(str) for idx, i in enumerate(img): r = np.array([-1,-1,-1,-1]) for jdx, j in enumerate(i): if (j == np.array(r)).all() : col_mat[idx][jdx] = "" else : col_mat[idx][jdx] = rgb.rgb256(j[0], j[1], j[2]) r = j # remove background A,B = np.where(img[:,:,3] == 0) for a,b in zip(A,B): if col_mat[a][b] != '': col_mat[a][b] = '\x1b[49m' return col_mat
def test_rgb(): from ansi.colour.rgb import rgb256 from ansi.colour.fx import reset msg = (rgb256(0xff, 0x80, 0x00), 'hello world', reset) assert ''.join(map(str, msg)) == '\x1b[38;5;214mhello world\x1b[0m'
def color_text(text, rgb_code): reset = '\x1b[0m' return rgb.rgb256(*rgb_code) + text + reset
from ansi.colour.fg import * from ansi.colour.rgb import rgb256 # Farben von rot nach grün um die Gewichtung der Verbindung darzustellen log_blend_colours = [ rgb256(255, 0, 0), rgb256(242, 81, 0), rgb256(228, 114, 0), rgb256(213, 140, 0), rgb256(198, 161, 0), rgb256(180, 180, 0), rgb256(161, 198, 0), rgb256(140, 213, 0), rgb256(114, 228, 0), rgb256(81, 242, 0), rgb256(0, 255, 0) ]
def f(x): brightness = int(x[0]) + int(x[1]) + int(x[2]) index = int(range_map(brightness, 0, 755, 0, len(chars) - 1)) # rbg256 and reset are from the ansi package and are for color msg = (rgb256(int(x[0]), int(x[1]), int(x[2])), chars[index], reset) return ''.join(map(str, msg))