speckles/speckles.py

115 lines
4.0 KiB
Python
Raw Normal View History

2023-05-18 14:15:37 +00:00
import itertools
import json
import random
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
def make_wallpaper(
background: str,
speckle_colours: list[str],
filename: str | Path,
2023-07-10 07:14:05 +00:00
density: int = 0.6,
2023-05-18 14:15:37 +00:00
dimensions: tuple[float | int, float | int] = (1920, 1080),
) -> None:
x, y = dimensions
2023-07-10 07:14:05 +00:00
speckles_per_colour = x / 100 * y / 100 * density
2023-05-18 14:15:37 +00:00
fig, ax = plt.subplots(figsize=(x / 100, y / 100), facecolor=background)
ax.set_facecolor(background)
[spine.set_color(background) for spine in ax.spines.values()]
plt.xticks([])
plt.yticks([])
plt.margins(0, 0)
for color, size in itertools.product(
speckle_colours,
np.logspace(1, 6, 8, base=2),
):
plt.scatter(
2023-07-10 07:14:05 +00:00
[random.random() * x / 8 for _ in range(speckles_per_colour)],
[random.random() * y / 8 for _ in range(speckles_per_colour)],
2023-05-18 14:15:37 +00:00
c=color,
s=size,
)
plt.tight_layout()
# plt.xlim(0, x)
# plt.ylim(0, y)
# plt.axis("off")
plt.savefig(
filename,
dpi=128,
bbox_inches="tight",
pad_inches=0,
)
# plt.show()
plt.close()
# palette = random.choice(palettes)
def speckles(palette):
for i, background in enumerate(palette):
speckle_colours = palette[:i] + palette[i + 1 :]
_id = "_".join(speckle_colours).replace("#", "")
speckle_colours += ["#000000", "#000000", "#ffffff"]
make_wallpaper(
background,
speckle_colours,
f"speckles/speckles_{_id}.png",
)
def night_sky(palette):
speckle_colours = palette + ["#ffffff"]
_id = "_".join(palette).replace("#", "")
make_wallpaper(
"#000000",
speckle_colours,
f"speckles/night_sky_{_id}.png",
)
2023-07-10 07:14:05 +00:00
if __name__ == "__main__":
palettes = [
{"colours": ["#eee4ab", "#e5cb9f", "#99c4c8", "#68a7ad"], "votes": 100000},
{"colours": ["#e4d192", "#cba0ae", "#af7ab3", "#80558c"], "votes": 100000},
{"colours": ["#eeeeee", "#e1d4bb", "#cbb279", "#537188"], "votes": 100000},
{"colours": ["#c0dbea", "#ba90c6", "#e8a0bf", "#fdf4f5"], "votes": 100000},
{"colours": ["#f5ffc9", "#b3e5be", "#a86464", "#804674"], "votes": 100000},
{"colours": ["#ffde7d", "#f6416c", "#f8f3d4", "#00b8a9"], "votes": 100000},
{"colours": ["#53354a", "#903749", "#e84545", "#2b2e4a"], "votes": 100000},
{"colours": ["#967e76", "#d7c0ae", "#eee3cb", "#b7c4cf"], "votes": 100000},
{"colours": ["#fc5185", "#f5f5f5", "#3fc1c9", "#364f6b"], "votes": 100000},
{"colours": ["#eaeaea", "#ff2e63", "#252a34", "#08d9d6"], "votes": 100000},
{"colours": ["#eeeeee", "#00adb5", "#393e46", "#222831"], "votes": 100000},
{"colours": ["#2cd3e1", "#a459d1", "#f266ab", "#ffb84c"], "votes": 100000},
{"colours": ["#ffe194", "#e8f6ef", "#1b9c85", "#4c4c6d"], "votes": 100000},
{"colours": ["#146c94", "#19a7ce", "#b0daff", "#feff86"], "votes": 100000},
{"colours": ["#4c3d3d", "#c07f00", "#ffd95a", "#fff7d4"], "votes": 100000},
{"colours": ["#8bacaa", "#b04759", "#e76161", "#f99b7d"], "votes": 100000},
{"colours": ["#146c94", "#19a7ce", "#afd3e2", "#f6f1f1"], "votes": 100000},
{"colours": ["#9ba4b5", "#212a3e", "#394867", "#f1f6f9"], "votes": 100000},
{"colours": ["#00ffca", "#05bfdb", "#088395", "#0a4d68"], "votes": 100000},
{"colours": ["#7c9070", "#9ca777", "#fee8b0", "#f97b22"], "votes": 100000},
{"colours": ["#002a19", "#000000", "#ffffff", "#e0512f"], "votes": 100000},
]
palette_files = ["colorhunt.json"]
for palette_file in palette_files:
with open(palette_file, "rt") as f:
palettes += json.load(f)
print(len(palettes))
palettes = [
palette["colours"]
for palette in palettes
if palette["votes"] > 30000 or len(palette["colours"]) > 5
]
print(len(palettes))
for palette in palettes:
night_sky(palette)
speckles(palette)