Last active
December 18, 2020 14:31
-
-
Save nick3499/c8c2317bff04c8e4c421aa78c8d7f6e8 to your computer and use it in GitHub Desktop.
Python: Generate Desktop Background Design: random.randrange(), input(), for loop, terminal color formatting
This file contains hidden or 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
#!/usr/bin/env python | |
'''Generate random colored background design.''' | |
from random import randrange | |
def generate_design(): | |
'''Generate random background design.''' | |
print('\x1b[1;34mEnter hex color\x1b[0m: (example: 50514f) or leave blank') | |
hex1 = input('hex 1: ').upper() or '000000' | |
hex2 = input('hex 2: ').upper() or '000000' | |
hex3 = input('hex 3: ').upper() or '000000' | |
hex4 = input('hex 4: ').upper() or '000000' | |
hex5 = input('hex 5: ').upper() or '000000' | |
hex_strs = hex1 + hex2 + hex3 + hex4 + hex5 | |
hex_pairs = [] | |
n = 0 | |
for i in range(0, 5): | |
hex_pairs.append([hex_strs[n:n+2], hex_strs[n+2:n+4], hex_strs[n+4:n+6]]) | |
n += 6 | |
ascii_nums = [] | |
for i in range(0, 5): | |
ascii_nums.append([int(hex_pairs[i][0], 16), int(hex_pairs[i][1], 16), | |
int(hex_pairs[i][2], 16)]) | |
colors = [] | |
for i in range(0, 5): | |
colors.append(f'\x1b[48;2;{ascii_nums[i][0]};{ascii_nums[i][1]};\ | |
{ascii_nums[i][2]}m \x1b[0m') | |
color_strings = '' | |
for i in range(0, 160): | |
color_strings += colors[randrange(0, 5)] | |
for i in range(0, 40): | |
print(color_strings) | |
if __name__ == '__main__': | |
generate_design() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment