Last active
October 9, 2024 03:58
-
-
Save delimitry/6a01cbe55657121a1f3d to your computer and use it in GitHub Desktop.
Revisions
-
delimitry revised this gist
Dec 21, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ A tool for scrolling input text as ASCII art text banner in console """ import os -
delimitry revised this gist
Dec 21, 2017 . 1 changed file with 65 additions and 52 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,66 +1,79 @@ # -*- coding: utf-8 -*- """ A tool for scrolling input text as ASCII art text banners in console """ import os import time from PIL import Image, ImageDraw, ImageFont def init_console(cols, lines): os.system('mode con: cols=%s lines=%s' % (cols, lines)) def clear_console(): os.system('cls' if os.name == 'nt' else 'clear') def get_text_size(font, text): return font.getsize(text) def text_to_ascii_text(font, text, cols, lines): """Convert text to ASCII art text banner""" image = Image.new('RGB', (cols - 1, lines - 1), (255, 255, 255)) draw = ImageDraw.Draw(image) draw.text((0, 0), text, fill='black', font=font) width, height = image.size pixels = image.load() # convert image pixels to ASCII art out = '' for y in range(height): for x in range(width): pix = pixels[x, y] if pix != (255, 255, 255): out += '#' else: out += ' ' out += '\n' return out def main(): """Main""" text = 'Scrolling ASCII text in console.' font = ImageFont.load_default() # font = ImageFont.truetype('arial.ttf', 16) # get size of space char space_width = get_text_size(font, ' ')[0] # get size of text text_height = get_text_size(font, text)[1] # resize console cols = 100 lines = int(text_height * 1.25) init_console(cols, lines) # add some padding to the text padding = ' ' * int(cols / space_width + 1) text = padding + text index = 0 try: while True: clear_console() print(text_to_ascii_text(font, text[index:], cols, lines)) index += 1 if index > len(text): index = 0 time.sleep(0.1) except KeyboardInterrupt: pass if __name__ == '__main__': main() -
delimitry created this gist
Jun 12, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import os import time from PIL import Image, ImageDraw, ImageFont def init_console(cols, lines): os.system('mode con: cols=%s lines=%s' % (cols, lines)) def clear_console(): os.system('cls' if os.name == 'nt' else 'clear') def get_text_size(font, text): return font.getsize(text) def text_to_ascii_text(font, text, cols, lines): image = Image.new('RGB',(cols - 1, lines - 1), (255, 255, 255)) draw = ImageDraw.Draw(image) draw.text((0, 0), text, fill='black', font=font) width, height = image.size pixels = image.load() # convert image text pixels to ascii out = '' for y in xrange(height): for x in xrange(width): pix = pixels[x, y] if pix != (255, 255, 255): out += '#' else: out += ' ' out += '\n' return out def main(): text = 'Scrolling ascii text in console.' font = ImageFont.load_default() #font = ImageFont.truetype('arial.ttf', 16) # get size of space char space_width = get_text_size(font, ' ')[0] # get size of text text_height = get_text_size(font, text)[1] # resize console cols = 100 lines = int(text_height * 1.25) init_console(cols, lines) # add some padding to the text padding = ' ' * (cols / space_width + 1) text = padding + text index = 0 try: while True: clear_console() print text_to_ascii_text(font, text[index:], cols, lines) index += 1 if index > len(text): index = 0 time.sleep(0.1) except KeyboardInterrupt: pass if __name__ == '__main__': main()