reformat with black

This commit is contained in:
xfnw 2022-01-26 21:20:29 -05:00
parent 863cc599e4
commit 328faa847e
2 changed files with 126 additions and 127 deletions

View file

@ -1,37 +1,37 @@
#!/bin/sh #!/bin/sh
''''exec /usr/bin/env python3 -u "$0" "$@" #''' """'exec /usr/bin/env python3 -u "$0" "$@" #"""
__doc__ = 'little script to make irc color art that will probably get you banned' __doc__ = "little script to make irc color art that will probably get you banned"
# whee, look at this sus shebang workaround to always cause # whee, look at this sus shebang workaround to always cause
# unbuffered mode lol # unbuffered mode lol
import sys,time,argparse import sys, time, argparse
from PIL import Image, ImageOps from PIL import Image, ImageOps
from color import closestColor from color import closestColor
def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER,SHARPNESS): def main(imgPath, delay, ASCIIWIDTH, COLORCHAR, FILLER, SHARPNESS):
im = Image.open(imgPath, 'r') im = Image.open(imgPath, "r")
im = ImageOps.scale(im, ASCIIWIDTH*SHARPNESS / im.width) im = ImageOps.scale(im, ASCIIWIDTH * SHARPNESS / im.width)
width, height = im.size width, height = im.size
pixel_values = list(im.getdata()) pixel_values = list(im.getdata())
currentPixel = 0 currentPixel = 0
for y in range(0, height, 2*SHARPNESS): for y in range(0, height, 2 * SHARPNESS):
line = [] line = []
lastColor=69420 lastColor = 69420
for x in range(0, width, SHARPNESS): for x in range(0, width, SHARPNESS):
color = closestColor(pixel_values[width*y+x]) color = closestColor(pixel_values[width * y + x])
if color == lastColor: if color == lastColor:
colorcode = '' colorcode = ""
else: else:
colorcode =COLORCHAR.format(color, color) colorcode = COLORCHAR.format(color, color)
line.append(colorcode+(FILLER[currentPixel % len(FILLER)])) line.append(colorcode + (FILLER[currentPixel % len(FILLER)]))
lastColor=color lastColor = color
currentPixel+=1 currentPixel += 1
print(''.join(line)) print("".join(line))
if delay: if delay:
time.sleep(delay) time.sleep(delay)
@ -39,18 +39,18 @@ def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER,SHARPNESS):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser("banter") parser = argparse.ArgumentParser("banter")
parser.add_argument("file") parser.add_argument("file")
parser.add_argument("-d",metavar='delay',default=0) parser.add_argument("-d", metavar="delay", default=0)
parser.add_argument("-w",metavar='width',default=80) parser.add_argument("-w", metavar="width", default=80)
parser.add_argument("-s",metavar='sharpness',default=4) parser.add_argument("-s", metavar="sharpness", default=4)
parser.add_argument("--colorfmt",metavar='format',default='\\x03{},{}') parser.add_argument("--colorfmt", metavar="format", default="\\x03{},{}")
parser.add_argument("--filler",metavar='filler',default='.') parser.add_argument("--filler", metavar="filler", default=".")
args = parser.parse_args() args = parser.parse_args()
main( main(
args.file, args.file,
float(args.d), float(args.d),
int(args.w), int(args.w),
args.colorfmt.encode().decode('unicode_escape'), args.colorfmt.encode().decode("unicode_escape"),
args.filler.encode().decode('unicode_escape'), args.filler.encode().decode("unicode_escape"),
int(args.s) int(args.s),
) )

195
color.py
View file

@ -1,99 +1,99 @@
EXTENDEDCOLORS = { EXTENDEDCOLORS = {
17: "#472100", 17: "#472100",
18: "#474700", 18: "#474700",
19: "#324700", 19: "#324700",
20: "#004700", 20: "#004700",
21: "#00472c", 21: "#00472c",
22: "#004747", 22: "#004747",
23: "#002747", 23: "#002747",
24: "#000047", 24: "#000047",
25: "#2e0047", 25: "#2e0047",
26: "#470047", 26: "#470047",
27: "#47002a", 27: "#47002a",
29: "#743a00", 29: "#743a00",
30: "#747400", 30: "#747400",
31: "#517400", 31: "#517400",
32: "#007400", 32: "#007400",
33: "#007449", 33: "#007449",
34: "#007474", 34: "#007474",
35: "#004074", 35: "#004074",
36: "#000074", 36: "#000074",
37: "#4b0074", 37: "#4b0074",
38: "#740074", 38: "#740074",
39: "#740045", 39: "#740045",
41: "#b56300", 41: "#b56300",
42: "#b5b500", 42: "#b5b500",
43: "#7db500", 43: "#7db500",
44: "#00b500", 44: "#00b500",
45: "#00b571", 45: "#00b571",
46: "#00b5b5", 46: "#00b5b5",
47: "#0063b5", 47: "#0063b5",
48: "#0000b5", 48: "#0000b5",
49: "#7500b5", 49: "#7500b5",
50: "#b500b5", 50: "#b500b5",
51: "#b5006b", 51: "#b5006b",
53: "#ff8c00", 53: "#ff8c00",
54: "#ffff00", 54: "#ffff00",
55: "#b2ff00", 55: "#b2ff00",
56: "#00ff00", 56: "#00ff00",
57: "#00ffa0", 57: "#00ffa0",
58: "#00ffff", 58: "#00ffff",
59: "#008cff", 59: "#008cff",
60: "#0000ff", 60: "#0000ff",
61: "#a500ff", 61: "#a500ff",
62: "#ff00ff", 62: "#ff00ff",
63: "#ff0098", 63: "#ff0098",
65: "#ffb459", 65: "#ffb459",
66: "#ffff71", 66: "#ffff71",
67: "#cfff60", 67: "#cfff60",
68: "#6fff6f", 68: "#6fff6f",
69: "#65ffc9", 69: "#65ffc9",
70: "#6dffff", 70: "#6dffff",
71: "#59b4ff", 71: "#59b4ff",
72: "#5959ff", 72: "#5959ff",
73: "#c459ff", 73: "#c459ff",
74: "#ff66ff", 74: "#ff66ff",
75: "#ff59bc", 75: "#ff59bc",
77: "#ffd39c", 77: "#ffd39c",
78: "#ffff9c", 78: "#ffff9c",
79: "#e2ff9c", 79: "#e2ff9c",
80: "#9cff9c", 80: "#9cff9c",
81: "#9cffdb", 81: "#9cffdb",
82: "#9cffff", 82: "#9cffff",
83: "#9cd3ff", 83: "#9cd3ff",
84: "#9c9cff", 84: "#9c9cff",
85: "#dc9cff", 85: "#dc9cff",
86: "#ff9cff", 86: "#ff9cff",
87: "#ff94d3", 87: "#ff94d3",
89: "#131313", 89: "#131313",
90: "#282828", 90: "#282828",
91: "#363636", 91: "#363636",
92: "#4d4d4d", 92: "#4d4d4d",
93: "#656565", 93: "#656565",
94: "#818181", 94: "#818181",
95: "#9f9f9f", 95: "#9f9f9f",
96: "#bcbcbc", 96: "#bcbcbc",
97: "#e2e2e2", 97: "#e2e2e2",
98: "#ffffff", 98: "#ffffff",
} }
MIRCCOLORS = { MIRCCOLORS = {
1: (0,0,0), 1: (0, 0, 0),
2: (0,0,127), 2: (0, 0, 127),
3: (0,147,0), 3: (0, 147, 0),
4: (255,0,0), 4: (255, 0, 0),
5: (127,0,0), 5: (127, 0, 0),
6: (156,0,156), 6: (156, 0, 156),
7: (252,127,0), 7: (252, 127, 0),
8: (255,255,0), 8: (255, 255, 0),
9: (0,252,0), 9: (0, 252, 0),
10: (0,147,147), 10: (0, 147, 147),
11: (0,255,255), 11: (0, 255, 255),
12: (0,0,252), 12: (0, 0, 252),
13: (255,0,255), 13: (255, 0, 255),
14: (127,127,127), 14: (127, 127, 127),
15: (210,210,210) 15: (210, 210, 210),
} }
@ -101,16 +101,16 @@ colors = {}
# copy the dict lol # copy the dict lol
for i in MIRCCOLORS: for i in MIRCCOLORS:
colors[i]=MIRCCOLORS[i] colors[i] = MIRCCOLORS[i]
for i in EXTENDEDCOLORS: for i in EXTENDEDCOLORS:
hex=EXTENDEDCOLORS[i].lstrip('#') hex = EXTENDEDCOLORS[i].lstrip("#")
# https://stackoverflow.com/a/29643643/9406294 # https://stackoverflow.com/a/29643643/9406294
rgb=tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)) rgb = tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4))
#print(rgb) # print(rgb)
colors[i]=rgb colors[i] = rgb
COLORS = colors COLORS = colors
@ -124,7 +124,6 @@ def closestColor(rgb):
diss = {} diss = {}
for cc in COLORS: for cc in COLORS:
rc, gc, bc = COLORS[cc] rc, gc, bc = COLORS[cc]
distance = abs(r-rc) + abs(g-gc) + abs(b-bc) distance = abs(r - rc) + abs(g - gc) + abs(b - bc)
diss[cc] = distance diss[cc] = distance
return min(diss, key=diss.get) return min(diss, key=diss.get)