parse arguments
This commit is contained in:
parent
ab92a235da
commit
3adab8b168
1 changed files with 40 additions and 27 deletions
67
banter.py
67
banter.py
|
@ -4,41 +4,54 @@ __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
|
import sys,time,argparse
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from color import closestColor
|
from color import closestColor
|
||||||
|
|
||||||
ASCIIWIDTH=80
|
|
||||||
COLORCHAR='\x03{},{}' # this will be String.format()'ted with two args
|
|
||||||
FILLER='.'
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER):
|
||||||
raise Exception('you must supply an image')
|
im = Image.open(imgPath, 'r')
|
||||||
|
width, height = im.size
|
||||||
|
pixel_values = list(im.getdata())
|
||||||
|
|
||||||
im = Image.open(sys.argv[1], 'r')
|
ipix = width // ASCIIWIDTH # // instead of / to devide with a round number
|
||||||
width, height = im.size
|
|
||||||
pixel_values = list(im.getdata())
|
|
||||||
|
|
||||||
ipix = width // ASCIIWIDTH # // instead of / to devide with a round number
|
asciiHeight = height // ipix // 2
|
||||||
|
|
||||||
asciiHeight = height // ipix // 2
|
currentPixel = 0
|
||||||
|
|
||||||
currentPixel = 0
|
for y in range(asciiHeight):
|
||||||
|
line = []
|
||||||
|
lastColor=69420
|
||||||
|
|
||||||
for y in range(asciiHeight):
|
for x in range(ASCIIWIDTH):
|
||||||
line = []
|
color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)])
|
||||||
lastColor=69420
|
if color == lastColor:
|
||||||
|
colorcode = ''
|
||||||
|
else:
|
||||||
|
colorcode =COLORCHAR.format(color, color)
|
||||||
|
line.append(colorcode+(FILLER[currentPixel % len(FILLER)]))
|
||||||
|
lastColor=color
|
||||||
|
currentPixel+=1
|
||||||
|
|
||||||
for x in range(ASCIIWIDTH):
|
print(''.join(line))
|
||||||
color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)])
|
if delay:
|
||||||
if color == lastColor:
|
time.sleep(delay)
|
||||||
colorcode = ''
|
|
||||||
else:
|
|
||||||
colorcode =COLORCHAR.format(color, color)
|
|
||||||
line.append(colorcode+(FILLER[currentPixel % len(FILLER)]))
|
|
||||||
lastColor=color
|
|
||||||
currentPixel+=1
|
|
||||||
|
|
||||||
print(''.join(line))
|
|
||||||
if len(sys.argv) > 2:
|
if __name__ == "__main__":
|
||||||
time.sleep(float(sys.argv[2]))
|
parser = argparse.ArgumentParser("banter")
|
||||||
|
parser.add_argument("file")
|
||||||
|
parser.add_argument("-d",metavar='delay',default=0)
|
||||||
|
parser.add_argument("-w",metavar='width',default=80)
|
||||||
|
parser.add_argument("--colorfmt",metavar='format',default='\\x03{},{}')
|
||||||
|
parser.add_argument("--filler",metavar='filler',default='.')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(
|
||||||
|
args.file,
|
||||||
|
float(args.d),
|
||||||
|
int(args.w),
|
||||||
|
args.colorfmt.encode().decode('unicode_escape'),
|
||||||
|
args.filler.encode().decode('unicode_escape')
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue