2020-11-11 16:31:08 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
2020-11-28 20:44:10 +00:00
Static text writer
2020-11-11 16:31:08 +00:00
pip3 install Hershey - Fonts
v0 .1 .0
Font list :
' futural ' , ' astrology ' , ' cursive ' , ' cyrilc_1 ' , ' cyrillic ' , ' futuram ' , ' gothgbt ' , ' gothgrt ' ,
' gothiceng ' , ' gothicger ' , ' gothicita ' , ' gothitt ' , ' greek ' , ' greekc ' , ' greeks ' , ' japanese ' ,
' markers ' , ' mathlow ' , ' mathupp ' , ' meteorology ' , ' music ' , ' rowmand ' , ' rowmans ' , ' rowmant ' ,
' scriptc ' , ' scripts ' , ' symbolic ' , ' timesg ' , ' timesi ' , ' timesib ' , ' timesr ' , ' timesrb '
2020-11-11 21:14:38 +00:00
Licensed under GNU GPLv3
2020-11-11 16:31:08 +00:00
by cocoa and Sam Neurohack
'''
from __future__ import print_function
import time
import argparse
import sys
from HersheyFonts import HersheyFonts
2020-11-28 20:44:10 +00:00
from os import path , getcwd
abspath , filename = path . split ( path . realpath ( __file__ ) )
sys . path . insert ( 0 , path . join ( abspath , " ../lib " ) )
from clitools import Clitools
2020-11-11 16:31:08 +00:00
2020-11-28 20:44:10 +00:00
argsparser = argparse . ArgumentParser ( description = " Text generator " )
2020-11-11 16:31:08 +00:00
argsparser . add_argument ( " -f " , " --fps " , help = " Frame Per Second " , default = 30 , type = int )
argsparser . add_argument ( " -v " , " --verbose " , action = " store_true " , help = " Verbose output " )
argsparser . add_argument ( " -t " , " --text " , help = " Text to display " , default = " hello " , type = str )
2020-11-28 20:44:10 +00:00
argsparser . add_argument ( " -p " , " --police " , help = " Herschey font to use. One of ( {} ) " . format ( " , " . join ( HersheyFonts ( ) . default_font_names ) ) , default = " futural " , type = str )
args = argsparser . parse_args ( )
fps = args . fps
verbose = args . verbose
text = args . text
fontname = args . police
cli = Clitools ( {
" verbose " : verbose ,
" looptime " : 1 / fps ,
" name " : " generator::text "
} )
2020-11-11 16:31:08 +00:00
# Useful variables init.
2020-11-28 20:44:10 +00:00
white = cli . rgb2int ( ( 255 , 255 , 255 ) )
red = cli . rgb2int ( ( 255 , 0 , 0 ) )
blue = cli . rgb2int ( ( 0 , 0 , 255 ) )
green = cli . rgb2int ( ( 0 , 255 , 0 ) )
color = 65280
shape = [ ]
thefont = HersheyFonts ( )
2020-11-11 16:31:08 +00:00
#thefont.load_default_font()
thefont . load_default_font ( fontname )
thefont . normalize_rendering ( 120 )
for ( x1 , y1 ) , ( x2 , y2 ) in thefont . lines_for_text ( text ) :
shape . append ( [ x1 , - y1 + 400 , color ] )
shape . append ( [ x2 , - y2 + 400 , color ] )
while True :
2020-11-28 20:44:10 +00:00
cli . startFrame ( )
print ( shape , flush = True ) ;
cli . endFrame ( )