def image_to_ascii(stop,pause_sound=False, guess_name=False): ''' separate image_to_ascii function to have guessing game. image_folder: where the images are stored (All images need to have 3-letter formats a.k.a. .jpegs won't work) img: string from stop.attrs img_txt: possible text string that would've already been generated ''' image_folder = os.listdir('images/') logging.debug('Image folder found.') img = str(stop.attrs["im"]).strip(string.whitespace) img_txt = img[:-4]+'.txt' logging.info(img_txt) #log image text for debugging play_music(stop) if img_txt in image_folder: with open('images/'+img_txt) as f: lines = f.read() print "Guess ascii by pressing enter!" for l in lines.split('\t'): time.sleep(1.5) print l else: ascii_string = ASC.image_diff('images/'+img) print type(ascii_string) fin = open('images/'+img_txt,'w') print "file opened" for i in range(len(ascii_string)): fin.write(ascii_string[i]+'\t') fin.close()
def ascii_challenge(stop): ''' separate image_to_ascii function to have guessing game. image_folder: where the images are stored (All images need to have 3-letter formats a.k.a. .jpegs won't work) img: string from stop.attrs img_txt: possible text string that would've already been generated ''' global rhymes global ats play_music(stop,True) #pauses music image_folder = os.listdir('images/') img = str(stop.attrs["im"]).strip(string.whitespace) img_txt = img[:-4]+'.txt' logging.debug("Image Text:",img_txt) #log image text for debugging play_music(stop) boss = str(stop.attrs["kw"]).strip(string.whitespace) if img_txt not in image_folder: #convert image to txt file if not already. print "Converting jpg to txt!" ascii_string = ASC.image_diff('images/'+img) fin = open('images/'+img_txt,'w') print "file opened" for i in range(len(ascii_string)): fin.write(ascii_string[i]+'\t') fin.close() with open('images/'+img_txt) as f: lines = f.read() print "Guess ascii by pressing enter!" for l in lines.split('\t'): while not msvcrt.kbhit(): time.sleep(1.2) print l break while msvcrt.kbhit(): play_music(stop,True) msvcrt.getch() print "_________________________________________________________________" print "What's your guess?" print boss boss_guess = raw_input(">>") if boss_guess[:2] == boss[:2]: play_music(stop) print "You guessed right! Here are 5 hashes and ats for your prowess!" rhymes += 5 ats += 5 return rhymes, ats else: print "You guessed wrong!" play_music(stop) return rhymes,ats
def image_to_ascii(stop): ''' separate image_to_ascii function to have guessing game. image_folder: where the images are stored img: img_txt: possible text string that would've already been generated ''' global hashes global ats image_folder = os.listdir('images/') img= str(stop.attrs["im"]).strip(string.whitespace) img_txt = img[:-4]+'.txt' play_music(stop) boss_kw = str(stop.attrs["nomen"]).strip(string.whitespace) if img_txt in image_folder: with open('images/'+img_txt) as f: lines = f.read() print "Guess ascii by pressing enter!" for l in lines.split('\t'): while not msvcrt.kbhit(): time.sleep(1.5) break print l while msvcrt.kbhit(): msvcrt.getch() play_music(stop,False) print "-----------------------------------------------" print "What's your guess?" boss_guess = raw_input(">>") if boss_guess == boss_kw: print "You guessed right! Here are 5 hashes and ats for your prowess!" hashes += 5 ats += 5 break else: #try: ascii_string = ASC.image_diff('images/'+img) print type(ascii_string) fin = open('../images/'+img_txt,'w') print "file opened" for i in range(len(ascii_string)): fin.write(ascii_string[i]+'\t') fin.close()
def ascii_challenge(stop,pause_sound=False): ''' separate image_to_ascii function to have guessing game. image_folder: where the images are stored (All images need to have 3-letter formats a.k.a. .jpegs won't work) img: string from stop.attrs img_txt: possible text string that would've already been generated ''' global hashes global ats global current_sound logging.debug('image_to_ascii function entered.') image_folder = os.listdir('images/') logging.debug('Image folder found.') img = str(stop.attrs["im"]).strip(string.whitespace) img_txt = img[:-4]+'.txt' logging.debug("Image Text:",img_txt) #log image text for debugging play_ascii(stop) boss_kw = str(stop.attrs["nomen"]).strip(string.whitespace) if img_txt in image_folder: with open('images/'+img_txt) as f: lines = f.read() print "Guess ascii by pressing enter!" for l in lines.split('\t'): while not msvcrt.kbhit(): time.sleep(1.2) break print l while msvcrt.kbhit(): current_sound.stop() msvcrt.getch() print "-----------------------------------------------" print "What's your guess?" print boss_kw boss_guess = raw_input(">>") if boss_guess == boss_kw: current_sound.play() print "You guessed right! Here are 5 hashes and ats for your prowess!" hashes += 5 ats += 5 return hashes, ats else: play_ascii(stop,False) else: print "Converting jpg to txt!" ascii_string = ASC.image_diff('images/'+img) print type(ascii_string) fin = open('images/'+img_txt,'w') print "file opened" for i in range(len(ascii_string)): fin.write(ascii_string[i]+'\t') fin.close() return hashes,ats