def convert(text, background, foreground): """ Converts regular text text to banner3D text """ # only uppercase text is accepted text = text.upper() # loop through letter rows for row in range(8): # loop through the charecters on the text for _, letter in enumerate(text): try: # get the correct ASCII row and letter string = LETTERS[letter][row] except Exception: raise Exception(f'\n\n\nSorry, the character \'{letter}\' is not currently avalible.') # initalize `new_string` new_string = "" # append colored charecters to final string for char in string: if char == "#": new_string += bold(foreground, char) else: new_string += bold(background, char) # print each letters correct row print(new_string, end="") # newline at end of ASCII row print("")
from colorize import bold print(bold('red', 'Colorizin!'))
def main(): """ Fire up the rest of the script and initalize the 'final_summary' faces. """ # Define the hair for all the figures. hair = "\n\tX*X*X*X*X*X*X\n" # Define the sad face. sad_no = """\t############# # # # 0 0 # # v # # ___ # # / \\ # # # ############# """ # Add the hair to the sad face. sad = bold("yellow", hair) sad += bold("white", sad_no) # Define the happy face. happy_no = """\t############# # # # 0 0 # # v # # # # \\___/ # # # ############# """ # Add hair to the happy face. happy = bold("yellow", hair) happy += bold("white", happy_no) # Define the crying face. not_happy_no = """\t############# # # # 0 0 # # ' v # # ___ # # / \\ # # # ############# """ # Add hair to the crying face. not_happy = bold("yellow", hair) not_happy += bold("white", not_happy_no) while True: # Get the data. info = get_info() # Choose the the appropriate face(smiley/frownie/crying). final_summary = '' if ("Cloud" in info["summary"]) or ("Overcast" in info["summary"]): final_summary = sad if ("Sun" in info["summary"]) or ("Clear" in info["summary"]): final_summary = happy if (info["precipProbability"] > 0.5) or ("Snow" in info["summary"]): final_summary = not_happy if "Rain" in info["summary"]: final_summary = not_happy # Print the info. pprint(info, final_summary) # Sleep before beginning again. sleep(60)
def pprint(data, final_summary): """ Print out all the data in a user-friendly way. """ # Clear the screen print("\033c") # Test for what color the 'temperature' tag should be. temp_color = "" if data["temperature"] > 50: temp_color = "red" else: temp_color = "blue" # Test for what color the 'feels like' tag should be. feels_color = "" if data["apparentTemperature"] > 50: feels_color = "red" else: feels_color = "blue" # Test for what color the 'humidity' tag should be. humid_color = "" if data["humidity"] < 0.50: humid_color = "yellow" else: humid_color = "blue" # Test for what unicode symbol for the 'Summary' tag should be. weather_icon = "" if ("Cloud" in data["summary"]) or ("Overcast" in data["summary"]): weather_icon = u"\u2601" elif ("Sun" in data["summary"]) or ("Clear" in data["summary"]): weather_icon = u"\u2600" elif data["precipProbability"] > 0.5: weather_icon = u"\u26C6" elif "Snow" in data["summary"]: weather_icon = u"\u2603" # Banner_3d title. convert("Weather status:", "blue", "green") # Print the temperature in the specified color. print(bold(temp_color, ("\n\nTemperature: " + str(data["temperature"])))) # Print the feels like temperature in the specified color. print( bold(feels_color, ("Feels like: " + str(data["apparentTemperature"])))) # Print the humidity in the specified color. print( bold(humid_color, ("Humidity: " + str(data["humidity"] * 100) + "%"))) # Print the probibility of precipitation in green. print( bold("green", ("Probibility of precipitation: " + str(data["precipProbability"])))) # Print the intensity of precipitation in green. print( bold("green", ("Intensity of precipitation: " + str(data["precipIntensity"])))) # Print the dew point in green. print(bold("green", ("Dew point: " + str(data["dewPoint"])))) # Print the summary in green, along with white unicode symbols describing the weather. print(bold("green", ("Summary: " + data["summary"])), " ", weather_icon * 5) # Print the wind gust speed in green. print( bold( "green", ("Wind gust speed: " + str(data["windGust"]) + " miles per hour"))) # Print the wind speed in green. print( bold("green", ("Wind speed: " + str(data["windSpeed"]) + " miles per hour"))) # Print the miles of visibility in green. print(bold("green", ("Visibility: " + str(data["visibility"]) + " miles"))) # Print the appropriate face(smiley/frownie/crying). print(bold("green", "\nMy summary: "), end="") print(final_summary)
def main(): """ main process that converts image and prints ascii art """ # initalise images # initalize color numpy arrays red = np.array((255, 0, 0)) black = np.array((0, 0, 0)) green = np.array((0, 255, 0)) yellow = np.array((255, 255, 0)) blue = np.array((0, 0, 255)) purple = np.array((255, 0, 255)) cyan = np.array((0, 255, 255)) white = np.array((255, 255, 255)) # initalize list of numpy array colors colors = [red, green, blue, cyan, yellow, purple, white, black] # initalize list of color strings str_clrs = [ 'red', 'green', 'blue', 'cyan', 'yellow', 'purple', 'white', 'black' ] images = { "python": Image.open("python.jpg"), } # enter choice choice = input("enter name of character: ") image = images[choice] # Define the ASCII characters asci = ['\u1D77', '\u25AE', u'\u213B'] # initialize text = '' len_chars = len(asci) step = 255 / len_chars value, value2 = 0, step x_pos, y_pos, z_pos = 0, 0, 0 # open and resize the image scale = image.height / 350 image = image.resize((int(image.width / scale), int(image.height / scale))) image = image.resize((int(image.width / 1), int(image.height / 2.3))) # For every pixel in the image... while y_pos < image.height: # Find its brightness brightness = sum(image.getpixel((x_pos, y_pos))) / len_chars # find its color color = image.getpixel((x_pos, y_pos)) # make value1 numpy array out of the color rgb color_array = np.array(color) # initalise the subtracted arrays list subtracted_arrays = [] # find the color the current pixel is closest to for item in colors: difference = np.abs(item - color_array) difference = sum(difference) subtracted_arrays.append(difference) minpos = subtracted_arrays.index(min(subtracted_arrays)) color = str_clrs[minpos] # Depending on its brightness, assign it an ASCII character while z_pos < len_chars: #print(value1, brightness, value2) if value <= brightness <= value2: #print(characters[z_pos]) text += bold(color, asci[z_pos]) break # increment variables value += step value2 += step z_pos += 1 # reset window and idx z_pos = 0 value = 0 value2 = step # next pixel same line x_pos += 1 # new line if x_pos == image.width - 1: text += '\n' y_pos += 1 x_pos = 0 # finally print the output print("\033c") print(text)