def createWordle_fromFile(fName, interActive=False, horizontalProbability=1.0): # the master function, creates the wordle from a given text file tokens = FR.tokenize_file_IntoWords(fName) tokens, freq = FR.tokenGroup(tokens) print('\n ===== Top', min(10, len(tokens)), 'most frequent tokens =====\n') for i in range(min(10, len(tokens))): s = freq[i] print(str(s) + (7 - len(str(s))) * ' ' + ': ' + tokens[i]) normalTokens = normalizeWordSize(tokens, freq, TOKENS_TO_USE, horizontalProbability) canvas_W, canvas_H = placeWords(normalTokens) wordle = drawOnCanvas(normalTokens, (canvas_W, canvas_H)) wordle.save(fName[0:-4] + '_wordle.png') print('the wordle image was sucessfully saved on the disc as <' + fName[0:-4] + '_wordle.png >') if interActive == True: # we allow the user to repaint the existing tokens with other color schemes as many times as they wish print( '\n=========== You may repaint the existing wordle with other color schemes =========== \n' ) print( 'To stop, please type the text inside the quotes: "q" folowed by Enter' ) print('To try a new scheme type any other char\n') version = 1 while True: userInput = input( str(version) + '. waiting for new user input ... ') if userInput == 'q': print('exiting...') break wordle = drawOnCanvas(normalTokens, (canvas_W, canvas_H)) newFileName = fName[0:-4] + '_wordle_v' + str(version) + '.png' wordle.save(newFileName) print('=== saved on the disc as <', newFileName, '>\n') version += 1
def createWordle_fromFile(fName): tokens = FR.tokenize_file_IntoWords(fName) tokens_with_freq = FR.tokenGroup(tokens) print('\n') for i in range(min(10, len(tokens_with_freq))): s = tokens_with_freq[1][i] print( str(s) + (7 - len(str(s))) * ' ' + ': ' + tokens_with_freq[0][i]) N_of_words = 150 tokens = normalizeWordSize(tokens_with_freq, N_of_words, 250, 15) finalPlaces = placeWords(tokens) wordle = drawOnCanvas(tokens, finalPlaces) wordle.save(fName[0:-4] + '_wordle.png') print('the wordle image was sucessfully saved on the disc as <' + fName[0:-4] + '_wordle.png >')