Compare commits
6 Commits
beb81771a8
...
main
Author | SHA1 | Date | |
---|---|---|---|
b97737f670
|
|||
651473975f
|
|||
050c1da950
|
|||
3220b6aa64
|
|||
b4e70c2245
|
|||
94489b5da2
|
@@ -1,9 +1,10 @@
|
||||
import random
|
||||
import json
|
||||
import random
|
||||
|
||||
from main import make_wallpaper
|
||||
from speckles import make_wallpaper
|
||||
|
||||
palettes = [
|
||||
{"colours": ["#DE4A21", "#6F04F2", "#490B1C", "#4a9c9e"], "votes": 1000000},
|
||||
{"colours": ["#eee4ab", "#e5cb9f", "#99c4c8", "#68a7ad"], "votes": 100000},
|
||||
{"colours": ["#e4d192", "#cba0ae", "#af7ab3", "#80558c"], "votes": 100000},
|
||||
{"colours": ["#eeeeee", "#e1d4bb", "#cbb279", "#537188"], "votes": 100000},
|
||||
@@ -25,15 +26,23 @@ palettes = [
|
||||
{"colours": ["#00ffca", "#05bfdb", "#088395", "#0a4d68"], "votes": 100000},
|
||||
{"colours": ["#7c9070", "#9ca777", "#fee8b0", "#f97b22"], "votes": 100000},
|
||||
{"colours": ["#002a19", "#000000", "#ffffff", "#e0512f"], "votes": 100000},
|
||||
{"colours": ["#212248", "#EBAE36", "#C7C9F0", "#11088A"], "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:
|
||||
enabled_markers = "otY+xP*b"
|
||||
markers = random.choices(enabled_markers, k=random.randint(1, len(enabled_markers)))
|
||||
for i, palette in enumerate(palettes):
|
||||
colours = ["none"] + palette["colours"]
|
||||
b = make_wallpaper(
|
||||
",".join(colours), fileformat="png", size=2.1, density=0.3, local=True
|
||||
",".join(colours),
|
||||
fileformat="png",
|
||||
size=2.1,
|
||||
density=0.2,
|
||||
filename=f"wallpapers/speckles{i}_2880x1800.png",
|
||||
perlin=True,
|
||||
markers=enabled_markers,
|
||||
orientation="2880x1800",
|
||||
)
|
||||
# for body in b.body_iterator:
|
||||
# print(body)
|
||||
|
57
blob.py
Normal file
57
blob.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import svg
|
||||
from typing import Iterator, NamedTuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
RGen = np.random.default_rng()
|
||||
|
||||
|
||||
class Point(NamedTuple):
|
||||
x: float
|
||||
y: float
|
||||
|
||||
|
||||
def iter_body_points(size: int) -> Iterator[Point]:
|
||||
n_points = RGen.integers(3, 12) # how many points do we want?
|
||||
angle_step = (
|
||||
np.pi * 2 / n_points
|
||||
) # step used to place each point at equal distances
|
||||
for point_number in range(1, n_points + 1):
|
||||
pull = 0.75 * RGen.random() * 0.25
|
||||
angle = point_number * angle_step
|
||||
x = size + np.cos(angle) * size * pull
|
||||
y = size + np.sin(angle) * size * pull
|
||||
yield Point(x, y)
|
||||
|
||||
|
||||
def spline(points: list[Point], body_tension: int) -> Iterator[svg.PathData]:
|
||||
"""
|
||||
https://github.com/georgedoescode/splinejs
|
||||
"""
|
||||
yield svg.MoveTo(*points[-1])
|
||||
first_point = points[0]
|
||||
second_point = points[1]
|
||||
points.insert(0, points[-1])
|
||||
points.insert(0, points[-2])
|
||||
points.append(first_point)
|
||||
points.append(second_point)
|
||||
for p0, p1, p2, p3 in zip(points, points[1:], points[2:], points[3:]):
|
||||
yield svg.CubicBezier(
|
||||
x1=p1.x + (p2.x - p0.x) / 6 * body_tension,
|
||||
y1=p1.y + (p2.y - p0.y) / 6 * body_tension,
|
||||
x2=p2.x - (p3.x - p1.x) / 6 * body_tension,
|
||||
y2=p2.y - (p3.y - p1.y) / 6 * body_tension,
|
||||
x=p2.x,
|
||||
y=p2.y,
|
||||
)
|
||||
|
||||
|
||||
def blob(x, y, c, s, body_tension: int = 1) -> svg.Path:
|
||||
points = list(iter_body_points(s))
|
||||
return svg.Path(
|
||||
d=list(spline(points, body_tension)),
|
||||
fill=c,
|
||||
stroke="#000000",
|
||||
stroke_width=2,
|
||||
transform=[svg.Translate(x-s, y-s)],
|
||||
)
|
17
speckles.py
17
speckles.py
@@ -1,4 +1,5 @@
|
||||
import itertools
|
||||
from blob import blob
|
||||
import io
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pathlib import Path
|
||||
@@ -66,7 +67,7 @@ class Include(svg.Element):
|
||||
return self.text
|
||||
|
||||
|
||||
DEFINED = ".o+tYP-|sSex*"
|
||||
DEFINED = ".o+tYP-|sSex*b"
|
||||
|
||||
|
||||
def markertoSVG(marker, x, y, c, s):
|
||||
@@ -203,6 +204,8 @@ def markertoSVG(marker, x, y, c, s):
|
||||
)
|
||||
for angle in (0, 60, -60)
|
||||
]
|
||||
elif marker == "b":
|
||||
return blob(x, y, c, np.sqrt(s)*10)
|
||||
else:
|
||||
return svg.Use(
|
||||
href=f"#{marker}",
|
||||
@@ -244,7 +247,7 @@ def make_wallpaper(
|
||||
if perlin:
|
||||
gen = CoordsGenerator(x, y)
|
||||
|
||||
elements = [svg.Rect(width=x, height=y, color=background)]
|
||||
elements = [svg.Rect(width=x, height=y, fill=background)]
|
||||
style = svg.Style(
|
||||
text="\n".join(
|
||||
[f".c{colour[1:]} {{ fill: {colour}; }}" for colour in speckle_colours]
|
||||
@@ -293,8 +296,14 @@ def make_wallpaper(
|
||||
image.write_to_file(filename)
|
||||
return filename
|
||||
elif fileformat:
|
||||
buf = io.BytesIO(content.as_str().encode("utf-8"))
|
||||
buf.seek(0)
|
||||
if fileformat == "svg":
|
||||
buf = io.BytesIO(content.as_str().encode("utf-8"))
|
||||
buf.seek(0)
|
||||
elif fileformat in ["jpg", "png"]:
|
||||
with pyvips.Image.svgload_buffer(content.as_str().encode("utf-8")) as image:
|
||||
data = image.write_to_buffer("." + fileformat)
|
||||
buf = io.BytesIO(data)
|
||||
buf.seek(0)
|
||||
return StreamingResponse(content=buf, media_type=MEDIA_TYPES[fileformat])
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user