orientation option
This commit is contained in:
parent
c8444ed3b6
commit
b8011837e9
27
main.py
27
main.py
@ -1,4 +1,5 @@
|
||||
import io
|
||||
import logging
|
||||
import itertools
|
||||
import json
|
||||
import random
|
||||
@ -43,18 +44,34 @@ MEDIA_TYPES = {
|
||||
@app.get("/speckles/")
|
||||
def make_wallpaper(
|
||||
speckle_colours: str,
|
||||
dimensions: tuple[float | int, float | int] = (1920, 1080),
|
||||
density: float | None = 0.12,
|
||||
size: float | None = 3,
|
||||
fileformat: str = "svg",
|
||||
orientation: str | None = "landscape",
|
||||
):
|
||||
if not fileformat in MEDIA_TYPES:
|
||||
return
|
||||
speckle_colours = speckle_colours.split(",")
|
||||
background = speckle_colours.pop(0)
|
||||
x, y = dimensions
|
||||
speckles_per_colour = int(x / 100 * y / 100 * density)
|
||||
if orientation == "portrait":
|
||||
x, y = (1080, 1920)
|
||||
elif orientation == "landscape":
|
||||
x, y = (1920, 1080)
|
||||
elif "x" in orientation:
|
||||
resolution = orientation.split("x")
|
||||
if len(resolution) !=2 :
|
||||
logging.critical("input resolution has more or less than 2 dimensions")
|
||||
return
|
||||
x,y = resolution
|
||||
if all([x.isdigit(), y.isdigit()]):
|
||||
x,y = int(x), int(y)
|
||||
else:
|
||||
return
|
||||
else:
|
||||
x, y = (1920, 1080)
|
||||
speckles_per_colour = int(x / 128 * y / 128 * density)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(x / 100, y / 100), facecolor=background)
|
||||
fig, ax = plt.subplots(figsize=(x / 120, y / 120), facecolor=background)
|
||||
ax.set_facecolor(background)
|
||||
[spine.set_color(background) for spine in ax.spines.values()]
|
||||
ax.set_xticks([])
|
||||
@ -63,7 +80,7 @@ def make_wallpaper(
|
||||
|
||||
for color, size in itertools.product(
|
||||
speckle_colours,
|
||||
np.logspace(1, 6.6, 8, base=2),
|
||||
np.logspace(0, size, 10, base=np.exp(2)),
|
||||
):
|
||||
ax.scatter(
|
||||
[random.random() * x / 8 for _ in range(speckles_per_colour)],
|
||||
|
83
speckles.py
83
speckles.py
@ -8,44 +8,17 @@ from pathlib import Path
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
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", "coolors.json"]
|
||||
for palette_file in palette_files:
|
||||
with open(palette_file, "rt") as f:
|
||||
palettes += json.load(f)
|
||||
|
||||
|
||||
def make_wallpaper(
|
||||
background: str,
|
||||
speckle_colours: list[str],
|
||||
filename: str | Path,
|
||||
density: int = 20,
|
||||
density: int = 0.6,
|
||||
dimensions: tuple[float | int, float | int] = (1920, 1080),
|
||||
) -> None:
|
||||
x, y = dimensions
|
||||
speckles_per_colour = x / 100 * y / 100 * density
|
||||
|
||||
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()]
|
||||
@ -58,8 +31,8 @@ def make_wallpaper(
|
||||
np.logspace(1, 6, 8, base=2),
|
||||
):
|
||||
plt.scatter(
|
||||
[random.random() * x / 8 for _ in range(density)],
|
||||
[random.random() * y / 8 for _ in range(density)],
|
||||
[random.random() * x / 8 for _ in range(speckles_per_colour)],
|
||||
[random.random() * y / 8 for _ in range(speckles_per_colour)],
|
||||
c=color,
|
||||
s=size,
|
||||
)
|
||||
@ -101,9 +74,43 @@ def night_sky(palette):
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user