Last active
May 28, 2018 18:44
-
-
Save uktechreviews/be2bc2ce74e54a0bf776808be4df53c9 to your computer and use it in GitHub Desktop.
Code examples for Bible
This file contains 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 characters
# Test font size to determine the maximum number of characters per line and should match the default font used in draw_text | |
test_font = inkyphat.ImageFont.truetype(inkyphat.fonts.AmaticSC,20) | |
w, h = test_font.getsize("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
max_char = int((212/(w/36))) |
This file contains 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 characters
quotes = open("quotes", "r") | |
lines = quotes.readlines() | |
quotes.close() | |
maximum = len(lines) | |
choice=(randint(1,maximum-1)) | |
test = str(lines[choice]) | |
text = [test[i:i+max_char] for i in range(0,len(test),max_char)] |
This file contains 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 characters
for i in range(len(text)): | |
new_text=text[i] | |
if (new_text[max_char-1:max_char])!=" ": | |
new_text=new_text+"-" | |
if (new_text[-2:-1:])==".": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==",": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==";": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==":": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==" ": | |
new_text=new_text[:-1] | |
text[i]=new_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment