- Joined
- Feb 23, 2019
I just posted this on some other thread for fun, not the best when it comes to programming right now, but seems like I got a basic script working for generating random flags (of [insert-noun]-sexual), like all the ones people have made for the LGBTQ/etc.
Example:
Basic script:
On the same directory as the txt file, you execute the script so that it creates an HTML file with random flags and random names.
Example:
Basic script:
Python:
import random
flags_to_generate = 100
def generate_html(flags_list):
with open("flags_gen_html.html", "w", encoding="utf-8") as file:
file.write(f"""<!DOCTYPE html>
<html>
\t<head>
\t\t<title>Random flags</title>
\t\t<meta name="viewport" content="width=device-width, initial-scale=1.0">
\t\t<meta charset="UTF-8">
\t\t<base target="_blank">
\t\t<style>
\t\t\t:root{{--f_width:200;}}
\t\t\thtml{{font:21px Monospace;}}
\t\t\t::selection{{color:#fff;background:#704fad;}}
\t\t\tbody{{color:#fff;background:linear-gradient(0deg, #bdaadb, #beb4cd);margin:0rem;background-attachment:fixed;}}
\t\t\t.container{{display:flex;flex-wrap:wrap;}}
\t\t\t.box{{border:2px solid #8a77a9;border-radius:5px;margin:0.5rem;display:flex;flex-direction:column;overflow-wrap:anywhere;padding:0.5rem;align-items:center;background:#9b8bb5;max-width:calc(var(--f_width) * 1px);}}
\t\t\t.flag{{width:calc(var(--f_width) * 1px);height:calc(var(--f_width) * 1px / 1.9);background:#000;overflow:hidden;display:flex;}}
\t\t\tp{{margin:0.5rem 0rem 0rem 0rem;}}
\t\t</style>
\t</head>
\t<body>
\t\t<div class="container">
{'\n'.join(flags_list)}
\t\t</div>
\t</body>
</html>
""")
def generate_title():
with open("sexuality_ex.txt", "r", encoding="utf-8") as file:
chosen = next(file, "steve")
for i, line in enumerate(file, 1):
if i == random.randint(0, i):
chosen = line
return f"{chosen.strip().capitalize()}sexual"
def generate_color():
return "".join(f"{random.randint(0, 255):02x}" for i in range(3))
def generate_stripes(n, symmetrical):
flex_vals = [1, 2, 3, 4]
ratios = [1, 2, 2, 2]
output = []
irregular = 1 if random.randint(0, 3) >= 3 else 0
if symmetrical:
first_half = []
for i in range(n // 2):
if irregular:
first_half.append((generate_color(), random.choices(flex_vals, weights = ratios, k = 1)[0]))
else:
first_half.append((generate_color(), 1))
output.extend(first_half)
if n & 1:
if irregular:
output.append((generate_color(), random.choices(flex_vals, weights = ratios, k = 1)[0]))
else:
output.append((generate_color(), 1))
output.extend(first_half[::-1])
else:
if irregular:
first_half_thickness = []
for i in range(n // 2):
thickness_value = random.choices(flex_vals, weights = ratios, k = 1)[0]
first_half_thickness.append(thickness_value)
output.append((generate_color(), thickness_value))
if n & 1:
output.append((generate_color(), random.choices(flex_vals, weights = ratios, k = 1)[0]))
for i in range(n // 2):
output.append((generate_color(), first_half_thickness[-(i + 1)]))
else:
for i in range(n):
output.append((generate_color(), 1))
return output
def generate_flag_box():
direction = random.choice([1, 2])
flex_direction = "row" if direction == 1 else "column"
start = f"<div class=\"box\"><div class=\"flag\" style=\"flex-direction:{flex_direction};\">"
middle = ""
end = f"</div><p>{generate_title()}</p></div>"
n_stripes = random.randint(2, 9)
symmetrical = 0 if n_stripes < 3 else 1 if ((random.randint(0, 3) >= 1) and (n_stripes & 1)) else 0
stripes_colors = generate_stripes(n_stripes, symmetrical)
for color, thickness in stripes_colors:
middle += f"<div style=\"background:#{color};flex:{thickness};\"></div>"
return start + middle + end
generate_html([generate_flag_box() for n in range(flags_to_generate)])
On the same directory as the txt file, you execute the script so that it creates an HTML file with random flags and random names.