diff --git a/background.py b/background.py new file mode 100644 index 0000000..ece4320 --- /dev/null +++ b/background.py @@ -0,0 +1,39 @@ +import random +import json + +from main import make_wallpaper + +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}, +] +with open("popular.json", "r") as f: + palettes += json.load(f) + +palette = random.choice(palettes) +colours = ["black"] + palette["colours"] +with open("current_speckles.png", "wb") as f: + b = make_wallpaper( + ",".join(colours), fileformat="png", size=2.1, density=0.3, local=True + ) + # for body in b.body_iterator: + # print(body) diff --git a/main.py b/main.py index 06e0565..ebfde40 100644 --- a/main.py +++ b/main.py @@ -1,17 +1,12 @@ import io -import logging import itertools -import json +import logging import random -from collections import Counter -from copy import deepcopy -from datetime import datetime -from pathlib import Path import matplotlib.pyplot as plt import numpy as np import uvicorn -from fastapi import FastAPI, Response +from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse @@ -48,6 +43,7 @@ def make_wallpaper( size: float | None = 3, fileformat: str = "svg", orientation: str | None = "landscape", + local: bool = False, ): if not fileformat in MEDIA_TYPES: return @@ -59,12 +55,12 @@ def make_wallpaper( x, y = (1920, 1080) elif "x" in orientation: resolution = orientation.split("x") - if len(resolution) !=2 : + if len(resolution) != 2: logging.critical("input resolution has more or less than 2 dimensions") return - x,y = resolution + x, y = resolution if all([x.isdigit(), y.isdigit()]): - x,y = int(x), int(y) + x, y = int(x), int(y) else: return else: @@ -103,7 +99,13 @@ def make_wallpaper( pad_inches=0, ) buf.seek(0) - return StreamingResponse(content=buf, media_type=MEDIA_TYPES[fileformat]) + if local: + filename = f"speckles.{fileformat}" + with open(filename, "wb") as f: + f.write(buf.getbuffer()) + return filename + else: + return StreamingResponse(content=buf, media_type=MEDIA_TYPES[fileformat]) buf.close() diff --git a/speckles.py b/speckles.py index 7aa2f15..878e577 100644 --- a/speckles.py +++ b/speckles.py @@ -1,8 +1,6 @@ import itertools import json import random -from collections import Counter -from datetime import datetime from pathlib import Path import matplotlib.pyplot as plt