From 3f7391c80344936b2bfcd3ac4649e7beeb90e0f7 Mon Sep 17 00:00:00 2001 From: xfnw <xfnw@ttm.sh> Date: Fri, 18 Dec 2020 20:25:12 -0500 Subject: [PATCH 1/5] take the colors from mirc and ircdocs.horse stupid html tables --- .gitignore | 3 ++ banter.py | 0 color.py | 118 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 + 4 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100755 banter.py create mode 100644 color.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..417b7bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +__pycache__/* + diff --git a/banter.py b/banter.py new file mode 100755 index 0000000..e69de29 diff --git a/color.py b/color.py new file mode 100644 index 0000000..cd1e963 --- /dev/null +++ b/color.py @@ -0,0 +1,118 @@ +EXTENDEDCOLORS = { +17: "#472100", +18: "#474700", +19: "#324700", +20: "#004700", +21: "#00472c", +22: "#004747", +23: "#002747", +24: "#000047", +25: "#2e0047", +26: "#470047", +27: "#47002a", +29: "#743a00", +30: "#747400", +31: "#517400", +32: "#007400", +33: "#007449", +34: "#007474", +35: "#004074", +36: "#000074", +37: "#4b0074", +38: "#740074", +39: "#740045", +41: "#b56300", +42: "#b5b500", +43: "#7db500", +44: "#00b500", +45: "#00b571", +46: "#00b5b5", +47: "#0063b5", +48: "#0000b5", +49: "#7500b5", +50: "#b500b5", +51: "#b5006b", +53: "#ff8c00", +54: "#ffff00", +55: "#b2ff00", +56: "#00ff00", +57: "#00ffa0", +58: "#00ffff", +59: "#008cff", +60: "#0000ff", +61: "#a500ff", +62: "#ff00ff", +63: "#ff0098", +65: "#ffb459", +66: "#ffff71", +67: "#cfff60", +68: "#6fff6f", +69: "#65ffc9", +70: "#6dffff", +71: "#59b4ff", +72: "#5959ff", +73: "#c459ff", +74: "#ff66ff", +75: "#ff59bc", +77: "#ffd39c", +78: "#ffff9c", +79: "#e2ff9c", +80: "#9cff9c", +81: "#9cffdb", +82: "#9cffff", +83: "#9cd3ff", +84: "#9c9cff", +85: "#dc9cff", +86: "#ff9cff", +87: "#ff94d3", +89: "#131313", +90: "#282828", +91: "#363636", +92: "#4d4d4d", +93: "#656565", +94: "#818181", +95: "#9f9f9f", +96: "#bcbcbc", +97: "#e2e2e2", +98: "#ffffff", +} + + +MIRCCOLORS = { + 1: (0,0,0), + 2: (0,0,127), + 3: (0,147,0), + 4: (255,0,0), + 5: (127,0,0), + 6: (156,0,156), + 7: (252,127,0), + 8: (255,255,0), + 9: (0,252,0), + 10: (0,147,147), + 11: (0,255,255), + 12: (0,0,252), + 13: (255,0,255), + 14: (127,127,127), + 15: (210,210,210) +} + + +colors = {} + +# copy the dict lol +for i in MIRCCOLORS: + colors[i]=MIRCCOLORS[i] + +for i in EXTENDEDCOLORS: + hex=EXTENDEDCOLORS[i].lstrip('#') + + # https://stackoverflow.com/a/29643643/9406294 + rgb=tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)) + #print(rgb) + + colors[i]=rgb + + +COLORS = colors + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2ae5d14 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Pillow==8.0.1 + From 151fb732c82f5df8cd004167492cbdc3c18ced83 Mon Sep 17 00:00:00 2001 From: xfnw <xfnw@ttm.sh> Date: Fri, 18 Dec 2020 21:09:22 -0500 Subject: [PATCH 2/5] detect nearest colors --- color.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/color.py b/color.py index cd1e963..9f9edec 100644 --- a/color.py +++ b/color.py @@ -116,3 +116,12 @@ for i in EXTENDEDCOLORS: COLORS = colors +def closestColor(rgb): + r, g, b = rgb + diss = {} + for cc in COLORS: + rc, gc, bc = COLORS[cc] + distance = abs(r-rc) + abs(g-gc) + abs(b-bc) + diss[cc] = distance + return min(diss, key=diss.get) + From 137d4532c0fab0d8993b07b7756b16eee69015e0 Mon Sep 17 00:00:00 2001 From: xfnw <xfnw@ttm.sh> Date: Fri, 18 Dec 2020 21:09:39 -0500 Subject: [PATCH 3/5] convert images to irc! it works yey --- banter.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/banter.py b/banter.py index e69de29..8c26107 100755 --- a/banter.py +++ b/banter.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import sys,time +from PIL import Image +from color import closestColor + +ASCIIWIDTH=80 +COLORCHAR='\x03{},{}' # this will be String.format()'ted with two args +FILLER='.' + +if len(sys.argv) < 2: + raise Exception('you must supply an image') + +im = Image.open(sys.argv[1], 'r') +width, height = im.size +pixel_values = list(im.getdata()) + +ipix = width // ASCIIWIDTH # // instead of / to devide with a round number + +asciiHeight = height // ipix + +for y in range(asciiHeight): + line = [] + lastColor=69420 + + for x in range(ASCIIWIDTH): + color = closestColor(pixel_values[width*(y*ipix)+(x*ipix)]) + if color == lastColor: + colorcode = '' + else: + colorcode =COLORCHAR.format(color, color) + line.append(colorcode+FILLER) + lastColor=color + + print(''.join(line)) + if len(sys.argv) > 2: + time.sleep(float(sys.argv[2])) From 8a6c22f380f039b211ebe5af33feac51625dcc68 Mon Sep 17 00:00:00 2001 From: xfnw <xfnw@ttm.sh> Date: Fri, 18 Dec 2020 21:56:15 -0500 Subject: [PATCH 4/5] streach 1 pixel 2 tall, close enough lol --- banter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/banter.py b/banter.py index 8c26107..2dae349 100755 --- a/banter.py +++ b/banter.py @@ -17,14 +17,14 @@ pixel_values = list(im.getdata()) ipix = width // ASCIIWIDTH # // instead of / to devide with a round number -asciiHeight = height // ipix +asciiHeight = height // ipix // 2 for y in range(asciiHeight): line = [] lastColor=69420 for x in range(ASCIIWIDTH): - color = closestColor(pixel_values[width*(y*ipix)+(x*ipix)]) + color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)]) if color == lastColor: colorcode = '' else: From ff415b34ba89996edd3a9cfe30d1c1d69284aee5 Mon Sep 17 00:00:00 2001 From: owen <xfnw@ttm.sh> Date: Fri, 18 Dec 2020 22:00:38 -0500 Subject: [PATCH 5/5] add an image --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4ce58b6..abbdacc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # banter little script to make irc color art that will probably get you banned + +![irc art of a fox with a santa hat](https://camo.githubusercontent.com/c561d6bb149035725e895178ce744f0c05ed6c55e8d71d8fe01dcce015c8025a/68747470733a2f2f74746d2e73682f646c792e706e67) +