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,6 +1,6 @@
#!/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
@ -10,7 +10,7 @@ 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())
@ -24,14 +24,14 @@ def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER,SHARPNESS):
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),
) )

View file

@ -93,7 +93,7 @@ MIRCCOLORS = {
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),
} }
@ -104,7 +104,7 @@ 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))
@ -127,4 +127,3 @@ def closestColor(rgb):
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)