def check_answer(answer, Choise, current_line, answers, choises, table_line_length, shuffled_line, question): betuk = [' A: ', ' B: ', ' C: ', ' D: '] choise_lengths=[] for n in range(4): choise_lengths.append(len(shuffled_line[n])) choise_lengths=max(choise_lengths) for pos in range(len(answers)): if shuffled_line[pos] == current_line[0]: index = shuffled_line.index(shuffled_line[pos]) if answer == current_line[0]: choises[index] = Choise(betuk[index], shuffled_line[index], '\x1b[42m', '\x1b[39m', '\x1b[49m', '\x1b[30m',choise_lengths) fg.green = Style(RgbFg(0, 255, 0)) time.sleep(2) os.system('clear') play_sound("./msc/jo valasz.mp3", 0) print(fg.green + "Well done!" + fg.rs) else: play_sound("./msc/rossz valasz.mp3", 0) time.sleep(2) fg.red = Style(RgbFg(255, 0, 0)) print(fg.red+answer+"\nBetter luck next time!"+fg.rs) ask = safe_input("Would you like to play again? ('y'/'n')", ['y']) if ask == 'y': game_start() quiz() else: sys.exit(0) return choises
def __init__(self): super().__init__() # Add custom style attributes. self.purple = Style(Sgr(35)) self.blue = Style(Sgr(34)) self.orange = Style(RgbFg(255, 128, 0))
def __init__(self): super().__init__() self.set_renderfunc(Sgr, renderfunc.sgr) self.set_renderfunc(EightbitFg, renderfunc.eightbit_fg) self.set_renderfunc(RgbFg, renderfunc.rgb_fg) self.set_eightbit_call(EightbitFg) self.set_rgb_call(RgbFg) self.red = Style(Sgr(31)) self.green = Style(Sgr(32)) self.rs = Style(Sgr(39)) self.yellow = Style(RgbFg(250, 250, 70))
def __init__(self): fg.orange = Style(RgbFg(255, 150, 50)) #######Help_Crochet########### self.couleur_help_crochet = fg.orange self.bg_help_crochet = "" self.end_couleur_help_crochet = fg.rs self.end_bg_help_crochet = "" ########Help################## self.couleur_help = fg.da_green self.bg_help = "" self.end_couleur_help = fg.rs self.end_bg_help = "" ########Error################# self.couleur_error = fg.red self.bg_error = "" self.end_couleur_error = fg.rs self.end_bg_error = "" ########Info################## self.couleur_info = "" self.bg_info = bg.li_green self.end_couleur_info = "" self.end_bg_info = bg.rs
def transform_image(img): img = cv2.resize(img, (200, 200), interpolation=cv2.INTER_AREA) rgb_matrix = np.zeros((img.shape[0], img.shape[1])) for x in range(0, img.shape[0]): for y in range(0, img.shape[1]): rgb_matrix[x][y] = 0.21 * int(img[y][x][2]) + 0.72 * int( img[y][x][1]) + 0.07 * int(img[y][x][0]) ascii_matrix = np.full((img.shape[0], img.shape[1]), "") ascii_string = "`^\",:;Il!i~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$" for x in range(0, img.shape[0]): for y in range(0, img.shape[1]): ascii_matrix[x][y] = ascii_string[int( (rgb_matrix[x][y] / 255) * 64)] + ascii_string[int( (rgb_matrix[x][y] / 255) * 64)] + ascii_string[int( (rgb_matrix[x][y] / 255) * 64)] for x in range(0, img.shape[0]): for y in range(0, img.shape[1]): fg.color = Style( RgbFg(int(img[x][y][2]), int(img[x][y][1]), int(img[x][y][0]))) if (y == img.shape[1] - 1): print(fg.color + ascii_matrix[x][y] + fg.rs) else: print(fg.color + ascii_matrix[x][y] + fg.rs, end='')
def color(self): # Gets a list of RGB ('RGB') values of each frame if not self.framesRGB: self.framesRGB = [frame.image.get_data('RGB', -self.width*3) for frame in self.anim.frames] print('animation ready2run, running..\n') # Step through forever, frame by frame while True: for frame,frameL in zip(self.yielderRGB(), self.yielderL()): # Built up the string, by translating luminance values to characters outstr = '' # Define color from contigously stored RGB vals, map Luminance and repeat each char twice for correct aspect ratio for i in range(0,len(frame)-2,3): R = frame[i] G = frame[i+1] B = frame[i+2] pixel = frameL[i//3] fg.color = Style(RgbFg(R, G, B)) outstr += fg.color + self.chars[(int(pixel) * (self.len - 1)) // 255]*2 + fg.rs + \ ('\n' if (i + 3) % (self.width*3) == 0 else '') # Clear the console os.system(self.clear_console) # Write the current frame on stdout and sleep sys.stdout.write(outstr) sys.stdout.flush() #time.sleep(0.01) time.sleep(3)
def game_start(): fg.purple = Style(RgbFg(148, 0, 211)) pygame.mixer.init() os.system('clear') play_sound("./msc/loim_intro.wav", 0) time.sleep(2) print("This is the game of games..\nIn the arena..\nMr Steven Vágó is awaiting You!\n"+fg.purple+"Become the next Millionaire!\n"+fg.rs) circle.who_wants_to_be_a_millionaire_circle() time.sleep(5)
def fullColor(imgHeight, imgWidth, pixels): char = '█' for row in range(imgHeight): for col in range(imgWidth): fg.col = Style(RgbFg(pixels[col, row][0], pixels[col, row][1], pixels[col, row][2])) print(fg.col + char + fg.rs, end='') print(fg.col + char + fg.rs, end='') print()
def get_color(attr): if attr > 0: g = int(128 * attr) + 127 b = 128 - int(64 * attr) r = 128 - int(64 * attr) else: g = 128 + int(64 * attr) b = 128 + int(64 * attr) r = int(-128 * attr) + 127 fg.color = Style(RgbFg(r, g, b)) return fg.color
def highlight_rhyming_words(poem_file): with open(poem_file, 'r') as file: data = file.read() input = re.sub(r'[^\w\s]', '', data) input_list = re.findall(r'(\S+)\s*$(?!/)', input, re.MULTILINE) # initializing our sound dict sound_dict = {} already_rhymed = [] for i in input_list: sound_dict[i] = [] # rhyming for i in input_list: for n in input_list: if n != i: if n in pronouncing.rhymes(i) and n not in already_rhymed: sound_dict[i].append(n) already_rhymed.append(n) already_rhymed.append(i) # remove the non-rhymers for x in list(sound_dict.keys()): if sound_dict[x] == []: del sound_dict[x] # add the word itself to the values for k in sound_dict: sound_dict[k].append(k) # print out the final results # print(sound_dict) # optionally, and maybe more usefully, print out all rhyming values in a list rhyming_words = list(sound_dict.values()) # print("original poem:\n\n" + data) for rhyme_scheme in rhyming_words: #generate a color for the current scheme r_rand = np.random.choice(range(256)) g_rand = np.random.choice(range(256)) b_rand = np.random.choice(range(256)) fg.color = Style(RgbFg(r_rand, g_rand, b_rand)) for word in rhyme_scheme: # in here, we'd like to find and replace each word in the text file with it's associated fg.color word colored_word = fg.color + ef.bold + word + fg.rs + rs.bold_dim data = data.replace(word, colored_word) print(data)
def coloredASCII(imgHeight, imgWidth, pixels): ASCII = "`^\",:;Il!i~+-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$" for row in range(imgHeight): for col in range(imgWidth): bright = round(sum(pixels[col, row])/3) char = bright//4 fg.col = Style(RgbFg(pixels[col, row][0], pixels[col, row][1], pixels[col, row][2])) print(fg.col + ASCII[char] + fg.rs, sep='', end='') print(fg.col + ASCII[char] + fg.rs, sep='', end='') print()
def log(self, channel, message=""): fg.orange = Style(RgbFg(255, 150, 50)) icons = { "logo": (fg.white + ASCII_ART, fg.rs), "header": (" " + ef.bold, rs.bold_dim), "subheader": (ef.i + fg.white + " ", fg.rs + rs.i + "\r\n"), "info": (" " + "🤷 " + fg.white, fg.rs), "error": (" " + "💥 " + fg.orange, fg.rs), "check": (" " + "🎉 " + fg.green, fg.rs), "phone": (" " + "📱", ""), "end": ("\r\n", ""), } before, after = icons.get(channel, "") print(f"{before} {message} {after}")
print("Debug Mod On!\n") sys_debug=True; def exit(signum, frame): print('\n Stoped '+_info.name+'! \n') sys.exit() signal.signal(signal.SIGINT, exit) signal.signal(signal.SIGTERM, exit) # Font, Colors ef.end = '\033[0m' # ef.italic for italic ef.blod = '\033[1m' ef.underline = '\033[4m' # fg.rs for end fg.red=Style(RgbFg(255, 50, 50)) fg.orange = Style(RgbFg(255, 150, 50)) fg.gray = Style(RgbFg(165,165,165)) fg.green = Style(RgbFg(110,255,120)) ################################################# url='https://www.dcard.tw' url_board='/f' url_search=url+"/f/search?query=" print(fg.green+"Use \"Ctrl+C\" to exit. \n\tHave fun! ヽ(●´∀`●)ノ"+fg.rs+"\n") while True: # 查詢板塊 dcl_mode=input(ef.blod+"(1) Board URL (Default)\n(2) Board list select\n(3) Board keyword search (Not recommend)"+ef.end+fg.orange+"\nChoice mode: "+fg.rs).replace(" ","")
n_trials = 5 # number of trials n_updates = 300 # number of updates (name pictures "50.png", "100.png", etc. for every 50 updates) pos = (232, 226) # center pixel of top left cell width = 31 # pixel width of each cell gap = 1 # pixel gap between each cell cells = (21, 15) # size of dish (e.g. 21 x 15 cells) # Ancestor RGB color values: ancestors = [[0, 109, 219], [255, 109, 182], [220, 190, 0], [0, 93, 93], [182, 219, 255], [93, 20, 166], [254, 182, 219], [156, 82, 10], [182, 109, 255]] # Don't modify past here! # Colors for print_colored_cells function... comment out if you don't have sty installed bg.a1 = Style(RgbBg(ancestors[0][0], ancestors[0][1], ancestors[0][2])) bg.a2 = Style(RgbBg(ancestors[1][0], ancestors[1][1], ancestors[1][2])) bg.a3 = Style(RgbBg(ancestors[2][0], ancestors[2][1], ancestors[2][2])) bg.a4 = Style(RgbBg(ancestors[3][0], ancestors[3][1], ancestors[3][2])) bg.a5 = Style(RgbBg(ancestors[4][0], ancestors[4][1], ancestors[4][2])) bg.a6 = Style(RgbBg(ancestors[5][0], ancestors[5][1], ancestors[5][2])) bg.a7 = Style(RgbBg(ancestors[6][0], ancestors[6][1], ancestors[6][2])) bg.a8 = Style(RgbBg(ancestors[7][0], ancestors[7][1], ancestors[7][2])) bg.a9 = Style(RgbBg(ancestors[8][0], ancestors[8][1], ancestors[8][2])) colors = [bg.a1, bg.a2, bg.a3, bg.a4, bg.a5, bg.a6, bg.a7, bg.a8, bg.a9] # checks if pixel matches any ancestors and return the number. returns 0 if not matched def check_pixel(pixel): p = [pixel[x] for x in range(3)]
# ===== Start ===== Example("as namedtuple") from sty import fg as fg_obj fg = fg_obj.as_namedtuple() a = fg.yellow + "I have a yellow fg." + fg.rs print(a) # ===== End ===== # ===== Start ===== Example("copy") from sty import RgbFg, Style, fg fg_copy = fg.copy() fg_no_copy = fg fg.orange = Style(RgbFg(255, 200, 35)) # 'fg' and 'fg_no_copy' point to the same instance, therefore both can access 'orange': assert hasattr(fg, "orange") == True assert hasattr(fg_no_copy, "orange") == True # fg_copy is not effected by the changes made to the global 'fg' register-object. assert hasattr(fg_copy, "orange") == False # ===== End ===== print("Copy works if no exception was thrown.")
# from sty.rendertype import EightbitFg from .. import Example print("\n\nCUSTOMIZING\n" + "=" * 80) # ===== Start ===== Example("customizing the register-objects: assignment") from sty import RgbFg, Sgr, Style, ef, fg, rs fg.my_red = Style(RgbFg(255, 0, 0)) a = fg.my_red + "This text has red fg." + fg.rs print(a) # ===== End ===== # ===== Start ===== Example("customizing the register-objects: compose") from sty import RgbFg, Sgr, Style, ef, fg, rs fg.blue_bold = Style(RgbFg(0, 100, 200), Sgr(1)) fg.green_italic = Style(fg.green, ef.i) a = fg.blue_bold + "This text has bold blue fg." + rs.all b = fg.green_italic + "This text has italic green fg" + rs.all print(a, b, sep="\n") # ===== End ===== # ===== Start =====
if not os.path.isdir(songs_path): print(fg.yellow + "WARNING!!!! SONGS PATH IS INCORRECT") input() end() def getRecentJournal(): global journal_path journal_files = glob.glob(ED_Journal_Folder + "\\*.log") journal_path = max(journal_files, key=os.path.getmtime) pygame.mixer.init() #style stuff fg.orange = Style(RgbFg(255, 90, 0)) fg.yellow = Style(RgbFg(255, 204, 0)) title_fig = pyfiglet.Figlet(font='big') journal_path = '' current_user_dir = os.path.expanduser("~") ED_Journal_Folder = '' songs_path = '' battle_songs_path = '' battle_songs_enabled = True in_battle = False docking_reminder = False song_selection_method = "Shuffle" song_volume = 0.15 next_song_keybind = "l"
def print_colors(colors): for color in colors: fg.color = Style(RgbFg(color[0], color[1], color[2])) buf = fg.color + '■' + fg.rs print(buf, end=" ") log("")
def quiz(): Help_available = [True, True, True] prices = ["5.000 Ft", "10.000 Ft", "25.000 Ft", "50.000 Ft", "100.000 Ft", "200.000 Ft", "300.000 Ft", "500.000 Ft", "800.000 Ft", "1.500.000 Ft", "3.000.000 Ft", "5.000.000 Ft", "10.000.000 Ft", "20.000.000 Ft", "40.000.000 Ft"] prices1 = ['40.000.000 Ft', '20.000.000 Ft', '10.000.000 Ft', '5.000.000 Ft', '3.000.000 Ft', '1.500.000 Ft', '800.000 Ft', '500.000 Ft', '300.000 Ft', '200.000 Ft', '100.000 Ft', '50.000 Ft', '25.000 Ft', '10.000 Ft', '5.000 Ft'] prices2 = ['40.000.000 Ft', '20.000.000 Ft', '10.000.000 Ft', '5.000.000 Ft', '3.000.000 Ft', '1.500.000 Ft', '800.000 Ft', '500.000 Ft', '300.000 Ft', '200.000 Ft', '100.000 Ft', '50.000 Ft', '25.000 Ft', '10.000 Ft', '5.000 Ft'] question_lines = open_file('questions.txt', "r") list_of_answers = open_file('questions.txt', "r") starting_range = 0 ending_range = 4 max_choise=[] class Choise(): def __init__(self, letter, answer, firstpart, secondpart, thirdpart, additional, lengths=''): self.lengths=lengths self.additional = additional self.mark = "▏" self.quote = "◆" self.letter = letter self.answer = answer self.spaces = (self.lengths-(len(self.answer)))*" " +5*" "+"▕" self.firstpart = firstpart self.secondpart = secondpart self.thirdpart = thirdpart self.f_end = "◀" self.s_end = "▶" self.line = "-" self.slash = "▕" self.slash_ = "▏" letters_ = [" A: ", " B: ", " C: ", " D: "] for i in range(15): counter = i random_question = [] random_question = random.choice(list_of_answers[starting_range:ending_range]) question = random_question[0] time.sleep(2) os.system('clear') current_line = random_question[1:5] copy_of_list_of_answers = copy.deepcopy(random_question) shuffled_line = copy_of_list_of_answers[1:5] random.shuffle(shuffled_line) a = shuffled_line[0] b = shuffled_line[1] c = shuffled_line[2] d = shuffled_line[3] choise_lengths=[] answers = [a, b, c, d] choises = [' ', ' ', ' ', ' '] for n in range(4): choise_lengths.append(len(shuffled_line[n])) choise_lengths=max(choise_lengths) for letter_ in range(len(letters_)): choises[letter_] = Choise(letters_[letter_],shuffled_line[letter_],'\x1b[40m','\x1b[39m','\x1b[49m','\x1b[38;2;255;150;50m',choise_lengths) fg.orange = Style(RgbFg(255, 150, 50)) table_line_length = calculate_quiz_table_size(question_lines,list_of_answers) print_lists(Help_available, table_line_length) quiz_table(table_line_length, choises, question, shuffled_line) answer = safe_input("\nSelect the correct answer (a,b,c,d) or 'h' for help! ", ["a", "b", "c", "d", "h", "s"]) pressed_h_key(answer,answers, current_line, question, table_line_length, shuffled_line, choises, Help_available, prices, prices1, prices2, counter) list_of_are_you_sure_sound_files = ["./msc/vegleges.mp3", "./msc/vegleges2.mp3", "./msc/vegleges3.mp3", "./msc/vegleges4.mp3", "./msc/vegyem_veglegesnek.mp3"] are_you_sure_sound = choose_random_from_list(list_of_are_you_sure_sound_files) play_sound(are_you_sure_sound, 0) time.sleep(1) answer = safe_input("Are you sure? ", ["a", "b", "c", "d", "s"]) stop_game_and_guess_out_of_game(answer, Help_available, table_line_length, prices, prices1, prices2, counter,current_line, answers, choises, shuffled_line, question) answer=marking(Choise, answer, current_line, answers, choises, table_line_length, shuffled_line, question, Help_available)[1] os.system('clear') print_lists(Help_available, table_line_length) quiz_table(table_line_length, choises, question, shuffled_line) play_sound("./msc/marked.mp3", 0) time.sleep(4) #check_answer(answer, Choise, current_line, answers, choises, table_line_length, shuffled_line, question) choises=check_answer(answer, Choise, current_line, answers, choises, table_line_length, shuffled_line, question) print_lists(Help_available, table_line_length) quiz_table(table_line_length, choises, question, shuffled_line) time.sleep(2) os.system('clear') won_prize = prices[i] if i == 4: won_prize = "You have guaranteed 100.000 Ft" time.sleep(1) elif i == 9: won_prize = "You have guaranteed 1.500.000 Ft" time.sleep(1) elif i == 14: won_prize = fg.orange + "Congratulations!\nYou've just won the unbelivable 40.000.000 Ft\n"+fg.purple+"You became the new Millionaire!!!" + fg.rs print(won_prize) time.sleep(3) sys.exit(0) price_len=len("▏40.000.000 Ft▕")-4 print_lists(Help_available, table_line_length) print(" "+bg.black+"/"+"‾"*(table_line_length)+"\\"+price_len*" "+bg.rs) width = table_line_length len_table = len("‾"*(table_line_length-len(won_prize))) print(bg.black+"-"+"‹" + fg.orange + ''.join(won_prize).center((width), ' ') + fg.rs +" "+ "›" + "-"+(price_len-2)*" "+bg.rs) print(bg.black+" "+"\\"+"_"*(table_line_length)+"/"+price_len*" "+bg.rs) for line in range(6): print(bg.black+108*" "+bg.rs) starting_range = ending_range + 1 ending_range = starting_range + 4 time.sleep(1)
def orange(text): fg.orange = Style(RgbFg(255, 150, 50)) return fg.orange + text + fg.rs
"id": id, "name": name, "initial_logs": initial_logs, "current_logs": content }) running_containers.append(id) # for visual pleasure for i in running_containers_data: name = i["name"] spaces_to_be_added = longest_name_length - len(name) name += ' ' * spaces_to_be_added r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) fg.color = Style(RgbFg(r, g, b)) i["name"] = fg.color + name.capitalize() + fg.rs def line_formater(line, container_name): try: parsed = json.loads(line) time = parse(parsed['time']).astimezone(time_zone) milliseconds = int( round( time.strptime(time.strftime('%d.%m.%Y %H:%M:%S,%f'), '%d.%m.%Y %H:%M:%S,%f').timestamp() * 1000)) actual_log = '%s | %s | %s' % (container_name, time.strftime('%H:%M:%S %Y-%m-%d'), parsed["log"].split('\n')[0]) return [actual_log, milliseconds]
to_remove.append(algo) #removal process for ele in to_remove: algorithms.remove(ele) #print("Len of algorithms: " + str(len(algorithms))) #print("Len of images: " + str(len(images))) for i in range(len(algorithms)): self.algorithms[images[i]] = algorithms[i] NUM_SCRAMBLE_MOVES = 0 bg.orange = Style(RgbBg(255, 150, 50)) class Color(Enum): RED = bg.red GREEN = bg.green BLUE = bg.blue WHITE = bg.white ORANGE = bg.orange YELLOW = bg.yellow colors = ["Red", "Green", "Blue", "White", "Orange", "Yellow"] COLOR_MAP = { "Red": bg.red, "Green": bg.green,
from fake_useragent import UserAgent # 偽裝請求 from sty import fg, bg, ef, rs, Style, RgbFg def set_header_user_agent(): user_agent = UserAgent() return user_agent.random # Font, Colors ef.end = '\033[0m' # ef.italic for italic ef.blod = '\033[1m' ef.underline = '\033[4m' # fg.rs for end fg.orange = Style(RgbFg(255, 150, 50)) fg.gray = Style(RgbFg(165, 165, 165)) fg.gray_light = Style(RgbFg(125, 125, 125)) ################################################# def run_dcl(check="n"): check = check.lower() if check != "y" and check != "yes": pass def main(url, url_board, sys_debug=False): while True: req_url = url + url_board
# ===== Start ===== Example("gettings started: sty all the strings") from sty import fg, bg, ef, rs foo = fg.red + 'This is red text!' + fg.rs bar = bg.blue + 'This has a blue background!' + bg.rs baz = ef.italic + 'This is italic text' + rs.italic qux = fg(201) + 'This is pink text using 8bit colors' + fg.rs qui = fg(255, 10, 10) + 'This is red text using 24bit colors.' + fg.rs # Add custom colors: from sty import Style, RgbFg fg.orange = Style(RgbFg(255, 150, 50)) buf = fg.orange + 'Yay, Im orange.' + fg.rs print(foo, bar, baz, qux, qui, buf, sep='\n') # ===== End ===== # ===== Start ===== Example("gettings started: select dynamically") a = ef('italic') + 'Italic text.' + rs.italic b = fg('blue') + 'Blue text.' + rs.fg c = bg(randint(0, 254)) + 'Random colored bg' + rs.bg print(a, b, c, sep='\n') # ===== End =====
from sty import fg, Style, RgbFg # It's necessary to initialise colors by adding it to fg fg.brown_1 = Style(RgbFg(191, 92, 0)) fg.brown_2 = Style(RgbFg(150, 84, 23)) fg.brown_3 = Style(RgbFg(117, 60, 7)) brown_colors = (fg.brown_1, fg.brown_2, fg.brown_3) fg.green_1 = Style(RgbFg(34, 139, 34)) fg.green_2 = Style(RgbFg(0, 128, 0)) fg.green_3 = Style(RgbFg(0, 100, 0)) green_colors = ( fg.green_1, fg.green_2, fg.green_3, ) class Symbols: leaf = "&" wood_u = "|" wood_h = "~" wood_r = "/" wood_l = "\\" class Directions: RIGHT = "right" LEFT = "left" UP = "up"