10 Commits

15 changed files with 1128 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
"""Draw all twelve reference marks, or export one with --mark 1..12."""
import argparse
import json
from math import cos, sin, pi, radians
from pathlib import Path
from generate import gradient, trefoil
DIRECTORY = Path(__file__).resolve().parent
NAMES = (
"Crossed horizontal bands", "Nested rings", "Vertical split", "Diagonal weave",
"Opposing caps", "Diagonal fold", "Three petals", "Horizontal belt",
"Stepped wrap", "Vertical weave", "Open wave", "Open helix",
)
def outline(points):
"""Blend adjacent contour segments into a closed cubic spline."""
commands = [f"M{points[0][0]},{points[0][1]}"]
for i, a in enumerate(points):
prev, b, after = (points[j % len(points)] for j in (i-1, i+1, i+2))
# Short handles preserve tight crossings and narrow gaps.
c = [a[k] + (b[k]-prev[k])*.10 for k in (0, 1)]
d = [b[k] - (after[k]-a[k])*.10 for k in (0, 1)]
commands.append(f"C{c[0]:.2f},{c[1]:.2f} {d[0]:.2f},{d[1]:.2f} {b[0]},{b[1]}")
return "".join(commands) + "Z"
def rings():
"""Project parallel latitude bands, keeping the lower pole in view."""
strips = []
palette = [("#ffddad", "#ffd5be"), ("#ffaf92", "#ffa38c"),
("#ffdab3", "#ffc4a6"), ("#ff927c", "#ffa58b"),
("#ffc392", "#ffe1ba")]
eye = radians(27)
for front in (False, True):
bands = [(-83, -59), (-52, -31), (-23, -2), (7, 24), (35, 47), (58, 74)]
for row in reversed(range(len(bands))):
low, high = bands[row]
points = []
for lat, steps in [(low, range(81)), (high, reversed(range(81)))]:
lat = radians(lat)
for j in steps:
lon = pi*(j/80 + int(not front))
x = cos(lat)*cos(lon)
y = sin(lat)*cos(eye) + cos(lat)*sin(lon)*sin(eye)
points.append(f"{50+45*x:.2f},{50-45*y:.2f}")
colors = palette[row % len(palette)] if front else ("#8f8498", "#a27085")
name = f"ring-{row}-{int(front)}"
strips.append(gradient(name, colors))
strips.append(f'<polygon points="{" ".join(points)}" fill="url(#{name})"/>')
return "".join(strips)
def belt():
paths = []
for i, (shape, colors) in enumerate([
("M20 19C27 3 69 2 79 18C82 25 17 25 20 19Z", ("#a9637b", "#783753")),
("M6 42C7 29 91 28 94 41L94 61C92 73 9 73 6 60Z", ("#88849a", "#c4d5d1")),
("M6 42C7 29 91 28 94 41C83 49 18 50 6 42Z", ("#64516e", "#93889c")),
("M6 60C14 52 84 54 94 61C91 72 10 73 6 60Z", ("#67516c", "#8c8194")),
("M19 79C24 72 73 72 80 78C72 99 32 101 19 79Z", ("#ff947f", "#ffcaab")),
]):
name = f"belt-{i}"
paths.extend([gradient(name, colors), f'<path d="{shape}" fill="url(#{name})"/>'])
return "".join(paths)
def symbol(index, layers):
if index == 1:
art = rings()
elif index == 6:
art = f'<g transform="translate(50 50) scale(.37)">{trefoil()}</g>'
elif index == 7:
art = belt()
else:
art = traced_faces(index, layers)
return f'<g id="mark-{index+1:02}"><title>{NAMES[index]}</title>{art}</g>'
def traced_faces(index, layers):
paths = []
for number, (left, right, loops) in enumerate(layers):
ident = f"g{index}-{number}"
paths.append(f'<linearGradient id="{ident}"><stop stop-color="{left}"/>'
f'<stop offset="1" stop-color="{right}"/></linearGradient>')
curves = "".join(outline(loop) for loop in loops)
paths.append(f'<path d="{curves}" fill="url(#{ident})" fill-rule="evenodd" '
f'stroke="url(#{ident})" stroke-width=".55" stroke-linejoin="round"/>')
return "".join(paths)
def draw(mark=None):
layers = json.loads((DIRECTORY / "contours.json").read_text())
if mark:
width = height = 100
shapes = [symbol(mark-1, layers.get(str(mark)))]
else:
width, height = 680, 460
shapes = []
for i in range(len(NAMES)):
x, y = 50 + i % 4 * 160, 32 + i // 4 * 148
shapes.append(f'<g transform="translate({x} {y})">{symbol(i, layers.get(str(i+1)))}</g>')
background = '' if mark else '<rect width="100%" height="100%" fill="#421743"/>'
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}" '
f'width="{width}" height="{height}">{background}' + "\n".join(shapes) + '</svg>\n')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--mark", type=int, choices=range(1, 13))
parser.add_argument("--output", type=Path)
args = parser.parse_args()
target = args.output or DIRECTORY / (f"mark-{args.mark:02}.svg" if args.mark else "catalogue.svg")
target.write_text(draw(args.mark), encoding="utf-8")
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 112 KiB

+11
View File
@@ -0,0 +1,11 @@
{
"1": [["#fad3c5","#fbc1b3",[[[47.0,30.7],[49.8,30.4],[53.8,31.1],[80.2,37.2],[90.4,36.5],[90.9,38.0],[90.4,39.0],[83.7,38.4],[77.7,39.4],[50.7,46.0],[47.2,45.8],[31.7,41.5],[20.9,39.5],[12.1,40.0],[8.5,41.9],[7.3,41.2],[7.6,37.9],[9.6,33.9],[14.5,36.7],[16.9,36.7],[34.1,34.1]]]],["#b9a3ad","#ae94a3",[[[47.0,64.5],[50.0,64.0],[55.0,64.8],[68.3,68.9],[83.4,71.6],[71.8,72.9],[50.2,78.7],[26.7,73.3],[17.8,73.6],[14.1,75.6],[12.8,74.4],[10.0,68.3],[10.0,67.6],[10.6,67.6],[15.4,70.3],[24.4,69.8]],[[87.5,70.9],[86.9,73.1],[86.7,71.6]]]],["#f8cdbb","#fac49c",[[[43.5,6.3],[54.7,5.8],[63.3,7.6],[74.3,13.0],[79.4,17.1],[80.7,19.3],[80.7,20.6],[78.9,21.9],[73.3,22.1],[60.3,19.9],[31.2,13.0],[29.2,12.0],[30.6,10.8],[37.9,7.6]]]],["#8a8797","#786e86",[[[74.9,40.0],[86.0,39.5],[91.4,41.2],[94.0,44.4],[93.4,50.3],[90.4,53.2],[84.9,54.7],[68.1,51.7],[55.3,48.2],[52.3,46.3],[53.5,45.3],[58.8,43.7]]]],["#8c8799","#8c879b",[[[77.2,57.5],[80.2,57.0],[87.9,57.5],[92.0,60.3],[92.4,63.3],[90.9,67.6],[87.5,70.1],[84.9,73.4],[75.1,72.9],[74.8,72.6],[75.7,72.3],[81.4,72.1],[83.4,71.4],[68.3,68.9],[54.0,64.6],[52.5,63.6],[52.7,62.8],[54.0,62.1],[65.9,59.0]]]],["#f78876","#f58778",[[[12.1,40.0],[20.9,39.5],[26.9,40.5],[44.7,44.9],[46.3,46.2],[42.4,48.2],[30.7,51.7],[18.6,53.5],[9.8,53.0],[6.6,50.3],[6.1,44.4],[6.8,42.7]]]],["#9f5e74","#8f4f6a",[[[12.0,54.0],[15.1,53.5],[17.1,54.2],[14.0,54.7]],[[10.0,57.6],[12.8,57.0],[20.9,57.0],[49.7,63.5],[34.1,67.8],[22.1,69.8],[16.3,69.8],[12.5,68.9],[9.5,67.1],[8.1,65.1],[7.6,60.8],[8.1,59.3]]]],["#f5877a","#f4897a",[[[75.9,22.6],[78.4,22.4],[86.9,27.1],[89.7,31.2],[90.7,34.4],[90.2,35.9],[84.9,37.2],[80.2,37.2],[55.5,31.7],[52.3,30.1],[54.3,28.7],[74.9,24.1]],[[90.9,37.9],[92.4,39.5],[91.5,40.9],[90.7,40.7]],[[81.7,38.9],[84.9,38.4],[86.9,39.0],[83.7,39.5]]]],["#431b45","#4c173f",[[[47.0,17.9],[49.8,17.6],[53.8,18.3],[72.9,22.4],[74.4,23.4],[72.3,24.6],[52.7,29.4],[48.3,29.6],[31.7,25.2],[23.8,23.9],[22.3,22.9],[23.4,22.3],[27.9,22.1],[39.7,19.9]]]],["#b2bfc3","#a5acb0",[[[17.9,24.9],[24.4,24.4],[30.4,25.4],[45.7,28.7],[47.5,29.9],[43.4,31.7],[34.1,34.1],[14.5,36.7],[12.1,35.5],[10.5,33.7],[10.5,30.2],[14.0,26.7]]]],["#8c8697","#8d8598",[[[16.9,73.9],[19.8,73.3],[26.7,73.3],[31.7,74.1],[44.5,77.6],[46.5,78.9],[45.2,80.1],[39.9,81.7],[27.9,83.7],[22.8,83.1],[19.6,81.6],[15.9,78.2],[15.4,75.9]]]],["#91849a","#8e8596",[[[27.7,12.6],[40.0,14.6],[45.3,16.3],[46.5,17.3],[43.5,19.1],[27.9,22.1],[22.1,22.1],[19.6,21.1],[19.1,19.9],[20.6,17.1],[24.1,14.0]]]],["#f4b798","#f6c4a6",[[[63.3,86.5],[69.8,86.0],[72.1,86.9],[72.3,87.7],[70.8,89.4],[63.5,92.5],[54.3,91.0],[52.3,89.7],[55.3,87.9]]]],["#b2b9c1","#a7a2a9",[[[27.9,86.9],[30.2,86.0],[38.4,87.2],[43.4,88.0],[46.5,89.7],[44.7,91.2],[36.5,92.5],[29.1,89.5],[27.6,87.9]]]],["#f6d3d3","#fdcebb",[[[48.2,90.0],[52.7,90.4],[57.3,91.5],[59.1,92.7],[57.6,93.7],[54.7,94.2],[45.3,94.2],[42.4,93.7],[40.9,92.7],[42.7,91.5]]]]],
"3": [["#fcd5be","#fce4cf",[[[34.1,7.6],[34.9,7.8],[35.0,8.6],[33.7,14.0],[33.7,25.6],[39.2,51.5],[38.9,55.1],[34.7,69.6],[33.1,80.7],[33.6,86.2],[34.9,90.4],[34.6,91.2],[27.9,88.4],[23.3,84.7],[27.7,84.7],[30.2,83.7],[31.2,81.2],[30.6,76.4],[26.7,68.6],[14.5,49.8],[15.0,47.5],[20.8,40.5],[26.6,31.2],[30.9,21.6],[31.4,18.6],[30.7,15.8],[29.1,14.0],[26.2,13.5],[25.6,12.5],[27.9,10.5]]]],["#b4a9b4","#b493a2",[[[66.1,8.0],[67.8,7.8],[71.8,9.6],[75.9,12.5],[76.9,14.0],[73.3,14.0],[69.8,15.1],[68.9,16.6],[69.3,20.3],[70.8,24.6],[84.9,47.2],[82.6,54.7],[75.6,65.1],[69.3,78.6],[69.3,83.1],[70.3,84.4],[74.3,86.9],[66.9,91.0],[66.1,90.9],[65.8,89.9],[67.4,83.7],[67.4,76.7],[61.6,47.7],[67.4,19.8],[67.4,15.1],[65.8,9.0]]]],["#8d8098","#8d798b",[[[57.6,6.5],[62.8,6.3],[65.0,7.5],[66.9,12.1],[67.4,15.1],[67.4,19.8],[65.4,30.6],[63.3,40.0],[61.1,45.0],[57.8,32.9],[54.7,16.3],[55.3,10.0]],[[69.9,15.1],[70.9,15.4],[71.6,16.8],[71.6,18.3],[70.3,17.8],[71.6,25.2],[70.4,23.8],[68.9,18.3],[68.9,16.6]],[[61.1,51.3],[62.1,51.8],[63.1,54.3],[65.3,63.8],[67.4,76.7],[67.4,83.7],[65.3,90.9],[63.5,92.5],[60.5,93.0],[57.6,92.4],[55.8,90.7],[54.7,86.0],[54.7,80.2],[57.8,62.5]],[[71.3,74.6],[72.1,76.7],[72.1,81.4],[71.3,83.7],[70.3,84.1],[68.9,82.2],[68.9,80.6]]]],["#f7937d","#f9ad86",[[[24.8,14.3],[27.7,13.6],[29.7,14.5],[31.4,18.6],[30.9,21.6],[26.6,31.2],[23.1,37.0],[17.8,44.5],[14.5,48.2],[13.1,48.7],[6.3,43.7],[7.6,35.5],[12.8,24.4],[18.3,17.1]]]],["#99778a","#a06a81",[[[85.0,47.2],[86.7,48.2],[89.2,51.5],[94.5,54.8],[93.5,62.1],[89.4,71.9],[85.2,78.2],[80.1,83.6],[76.4,85.5],[73.6,85.4],[72.1,82.6],[72.6,71.4],[75.6,65.1],[82.6,54.7]]]],["#7b7186","#93949e",[[[13.0,50.8],[15.4,52.0],[27.6,70.1],[31.2,80.4],[30.7,83.1],[29.6,84.2],[27.7,84.7],[23.3,84.4],[19.4,82.9],[12.8,74.4],[9.6,68.3],[7.6,63.3],[6.1,55.8],[8.6,52.8]]]],["#784f6d","#6e2b56",[[[78.2,14.6],[80.1,15.3],[83.2,17.9],[88.4,25.6],[92.5,36.4],[93.2,43.9],[88.0,48.7],[86.7,48.2],[83.4,44.5],[76.7,34.9],[71.6,23.8],[72.1,14.8],[73.4,14.1]]]],["#a7b1b4","#b2bcc2",[[[36.9,6.6],[40.7,5.8],[44.2,7.0],[45.7,10.1],[46.5,15.1],[42.2,39.9],[40.2,47.2],[39.2,48.7],[38.0,46.8],[33.7,25.6],[34.2,11.0],[35.2,8.5]]]],["#f9c294","#fbca9c",[[[39.2,55.8],[39.9,55.8],[41.0,57.8],[45.3,79.1],[45.3,84.9],[44.0,89.5],[44.4,90.7],[43.4,91.9],[40.9,92.7],[37.5,92.5],[35.5,91.2],[34.1,88.0],[33.1,83.2],[35.5,65.8],[37.9,57.6]]]]],
"4": [["#beb6ba","#c0aab1",[[[44.9,26.2],[48.7,26.9],[61.0,36.7],[75.6,54.7],[79.9,62.0],[81.9,66.9],[82.6,73.3],[82.1,75.1],[80.9,76.2],[77.9,76.7],[72.9,75.9],[60.5,70.9],[55.3,65.6],[51.7,63.5],[49.8,59.5],[44.9,52.8],[30.7,42.5],[29.9,40.9],[30.2,39.5],[32.2,36.9],[39.2,29.9]]]],["#fde5c9","#fdc9b0",[[[11.0,47.0],[14.0,46.5],[17.9,47.2],[25.4,51.3],[26.7,55.8],[28.7,58.5],[35.9,66.4],[45.5,75.4],[46.2,77.9],[45.3,80.7],[43.9,82.6],[36.5,85.4],[31.6,84.7],[27.4,81.9],[23.3,77.9],[20.1,77.9],[20.1,79.9],[25.2,85.2],[33.6,91.2],[28.2,89.2],[20.6,84.1],[14.8,78.2],[12.0,74.1],[7.6,64.5],[5.8,57.0],[7.1,50.2],[8.6,48.2]],[[47.5,85.7],[47.8,86.0],[46.7,86.5]]]],["#f9beb0","#fbb3a3",[[[52.0,9.0],[54.7,8.1],[57.6,8.6],[64.0,11.6],[74.8,19.4],[81.7,26.4],[88.4,36.0],[91.4,42.4],[91.7,45.2],[90.4,48.5],[88.0,49.7],[86.4,49.7],[84.2,48.3],[74.8,35.7],[65.4,26.4],[50.5,15.8],[49.5,13.1],[50.3,10.8]]]],["#927e91","#9d7083",[[[49.8,16.1],[53.3,17.6],[65.4,26.4],[74.8,35.7],[81.2,44.4],[83.4,48.0],[83.9,50.2],[79.7,49.3],[66.9,43.5],[57.0,32.6],[51.5,22.9],[49.7,17.8]],[[71.6,49.0],[73.1,50.2],[73.3,51.5],[71.8,50.3]],[[67.8,49.8],[68.8,50.0],[68.6,50.5],[67.4,50.5]]]],["#aebdc0","#c7c4c6",[[[22.6,17.9],[26.7,17.4],[31.7,18.3],[36.9,20.1],[38.4,21.4],[37.9,22.8],[31.1,28.7],[24.1,37.7],[22.4,36.9],[20.6,34.1],[18.4,33.1],[15.6,35.7],[14.8,30.6],[15.1,22.9],[18.6,19.8]]]],["#83798d","#807789",[[[60.3,71.9],[62.0,71.8],[72.9,75.9],[80.1,76.9],[81.6,77.7],[81.9,79.6],[79.6,83.1],[76.6,84.7],[69.4,85.2],[66.6,84.6],[63.8,82.7],[60.1,73.6]],[[61.2,88.1],[60.2,89.1],[60.2,88.1]]]],["#f3ad87","#f19a89",[[[49.2,74.6],[50.8,75.9],[51.8,78.4],[52.2,81.2],[51.5,82.9],[49.7,84.6],[40.5,88.2],[39.5,89.4],[40.7,90.7],[46.3,93.4],[44.2,94.2],[36.9,93.4],[29.7,89.5],[28.6,87.7],[25.2,85.2],[19.8,79.4],[20.4,77.7],[23.3,77.9],[30.1,83.9],[33.2,85.4],[36.5,85.4],[49.8,80.1],[50.5,78.2],[48.5,75.4]]]],["#f4b591","#f9a993",[[[24.3,49.8],[27.7,51.3],[33.1,55.3],[43.4,64.8],[47.8,70.8],[50.5,78.2],[49.8,80.1],[48.3,80.9],[45.7,80.9],[47.0,74.6],[44.4,74.3],[35.9,66.4],[26.7,55.8],[26.2,53.0]]]],["#9e99a2","#a2a4b6",[[[53.2,81.4],[55.0,81.1],[62.1,84.1],[75.4,85.7],[70.8,89.4],[64.6,92.5],[57.0,94.2],[53.7,94.0],[52.3,93.2],[54.0,87.7]],[[61.2,88.1],[60.2,88.1],[60.2,89.1]]]],["#9e7f90","#a6747d",[[[59.6,8.6],[63.5,8.6],[70.9,11.6],[77.1,15.9],[84.1,22.9],[89.2,30.6],[92.4,39.0],[92.4,41.7],[90.9,40.5],[89.4,37.4],[81.7,26.4],[74.8,19.4],[66.1,13.0],[59.6,9.3]]]],["#b1b6bc","#abadb7",[[[17.3,33.6],[18.4,33.1],[20.6,34.1],[21.6,36.2],[21.3,37.2],[19.3,37.7],[17.8,36.9],[16.6,34.9]],[[15.6,38.2],[22.3,49.0],[17.9,47.2],[14.0,46.5],[9.3,47.7],[6.3,50.8],[5.8,44.2],[6.6,41.5],[8.3,39.7],[14.3,37.9]]]],["#f38b82","#e58c89",[[[92.4,44.5],[93.9,53.2],[92.2,63.1],[90.4,67.3],[89.7,66.1],[88.9,58.8],[85.7,51.8],[86.2,50.7],[90.4,48.5]]]],["#e0817e","#f28881",[[[41.2,7.5],[50.0,7.0],[52.0,7.5],[52.2,8.3],[49.5,12.3],[47.3,13.6],[31.6,10.8],[35.5,8.8]]]],["#ffd9c4","#f4d0c4",[[[52.5,83.7],[53.8,84.6],[54.0,87.7],[52.5,92.0],[51.3,93.2],[48.2,93.7],[41.5,91.0],[40.5,90.0],[41.7,88.2],[48.7,85.9]]]],["#8f5872","#975f71",[[[78.9,59.1],[83.6,59.5],[85.0,60.3],[85.9,61.8],[84.1,72.4],[83.2,74.1],[81.9,66.9]],[[88.9,60.8],[89.5,62.8],[89.5,67.4],[88.4,72.1],[86.9,73.3]]]],["#dbe2ea","#d8e6e9",[[[14.1,25.6],[15.1,32.6],[14.6,35.5],[13.0,37.4],[7.8,39.5],[7.6,37.9],[9.5,32.7],[12.8,26.7]]]]],
"5": [["#fbc1b2","#fbd4c8",[[[49.3,70.3],[52.8,70.4],[66.9,74.9],[76.7,76.7],[80.2,76.7],[86.5,75.2],[87.7,75.9],[80.6,85.2],[73.1,90.5],[63.3,94.7],[53.5,96.5],[46.5,96.5],[37.9,94.7],[31.2,92.0],[23.3,86.4],[25.7,83.1],[24.3,80.2],[25.4,78.9],[28.6,78.4],[30.2,79.2],[33.9,75.7]]]],["#aa93a1","#bdaeb4",[[[43.5,4.0],[54.7,3.5],[61.3,5.1],[59.6,10.3],[59.3,14.0],[60.0,26.6],[51.7,29.6],[46.2,29.4],[31.2,23.4],[28.4,20.4],[27.9,18.4],[29.2,15.9],[29.1,14.6],[30.2,13.3],[30.1,10.0],[30.7,8.6],[34.4,6.5]]]],["#786b83","#878394",[[[28.4,10.3],[29.7,11.0],[30.2,12.8],[27.9,18.4],[29.4,21.8],[31.2,23.4],[45.3,29.1],[46.7,30.7],[45.0,32.2],[40.0,34.2],[29.6,37.7],[20.1,39.9],[15.4,40.4],[10.1,38.7],[9.0,37.5],[8.1,34.9],[8.6,31.9],[11.5,25.4],[19.1,15.6],[25.7,10.6]]]],["#8f4c69","#9f5f77",[[[77.2,22.6],[84.6,23.6],[90.7,27.1],[92.5,30.7],[93.0,33.7],[91.7,38.2],[88.4,39.5],[81.4,39.5],[76.4,38.7],[57.6,33.1],[53.5,31.4],[52.3,30.1],[53.3,28.9],[61.1,26.2]]]],["#a2a9b0","#b1bfc1",[[[81.9,59.8],[84.9,59.3],[89.0,59.8],[90.7,60.5],[92.4,62.3],[93.0,65.1],[92.5,68.1],[89.5,73.8],[88.0,75.1],[80.2,76.7],[76.7,76.7],[58.8,72.6],[54.8,70.8],[53.7,69.4],[54.3,68.3],[64.5,64.5]]]],["#f78775","#f78778",[[[11.1,61.1],[18.6,60.5],[29.4,62.5],[44.4,67.3],[46.3,68.8],[46.5,70.4],[39.0,73.9],[30.6,75.9],[25.6,76.7],[16.8,76.2],[12.8,73.6],[10.5,72.9],[8.6,69.3],[8.5,64.3],[9.6,62.0]]]],["#c3b7bc","#d1c8ca",[[[61.3,6.6],[64.6,6.3],[75.4,10.6],[85.2,19.4],[88.2,23.4],[88.7,25.6],[84.6,23.6],[77.4,22.4],[61.0,25.1],[59.8,23.9],[59.3,22.1],[59.3,14.0],[60.3,7.6]]]],["#f7a99e","#f9b5a5",[[[12.1,73.6],[16.8,76.2],[25.6,76.7],[30.9,76.1],[31.6,77.2],[24.8,79.4],[24.3,80.2],[26.9,84.7],[24.9,85.2],[20.9,83.6],[19.8,83.9],[18.4,82.7],[12.6,75.7]]]],["#7b3a58","#792f46",[[[13.1,59.8],[16.3,59.3],[18.3,60.0],[15.1,60.5]],[[8.3,62.6],[8.5,64.3],[7.5,65.9],[7.3,64.3]]]],["#fda89a","#d0aeaf",[[[47.4,69.1],[48.4,70.0],[47.4,70.0]]]]],
"6": [["#fcca96","#f9ac87",[[[17.6,18.4],[15.3,22.3],[13.1,29.4],[14.0,33.7],[16.6,35.7],[19.8,36.0],[23.8,35.4],[39.5,29.1],[56.1,32.2],[68.9,35.7],[72.9,37.2],[73.3,38.7],[70.8,40.5],[58.6,44.7],[41.0,49.2],[29.1,51.2],[17.4,51.2],[13.5,50.5],[7.3,47.3],[5.8,45.3],[4.7,40.7],[5.3,36.7],[9.3,27.9],[13.6,21.8]]]],["#f88775","#f78777",[[[72.6,50.5],[80.2,50.0],[85.2,50.8],[89.5,52.3],[92.2,54.3],[94.2,57.0],[95.0,61.3],[93.7,66.9],[90.2,73.9],[87.7,75.6],[86.5,75.2],[86.7,69.1],[85.4,66.9],[83.2,65.6],[80.2,65.1],[77.2,65.6],[68.9,68.9],[64.0,72.1],[60.1,72.4],[27.4,64.5],[25.4,62.8],[27.4,61.1],[46.0,55.3],[60.3,52.2]]]],["#fbbeb0","#fdb8a8",[[[20.3,63.3],[24.9,63.5],[40.2,67.9],[58.3,71.9],[60.5,72.9],[60.8,73.9],[47.0,87.7],[45.8,88.5],[44.0,88.5],[24.1,77.1],[17.1,74.8],[12.5,75.7],[11.0,75.1],[8.1,70.9],[6.6,66.9],[7.1,65.8],[16.8,64.5]]]],["#fddac3","#fdddcf",[[[54.0,12.5],[56.8,13.0],[70.9,22.1],[79.7,26.1],[83.6,26.6],[88.0,25.4],[90.4,28.2],[93.2,36.2],[88.4,36.0],[74.8,38.9],[72.4,36.9],[68.9,35.7],[38.5,28.4],[38.9,27.2],[42.2,24.8]]]],["#9b7488","#a16c81",[[[63.1,73.1],[65.4,72.9],[72.1,74.4],[80.2,74.4],[85.9,72.9],[86.5,75.2],[88.4,75.6],[88.5,76.4],[85.2,81.7],[80.6,86.4],[74.4,90.7],[63.1,95.7],[58.1,96.5],[55.0,96.2],[47.2,91.2],[46.5,90.2],[46.7,88.5],[55.5,78.7]]]],["#81788d","#8f8e9d",[[[38.9,5.1],[45.0,5.0],[54.0,10.8],[50.3,16.6],[43.4,23.6],[37.5,27.9],[36.2,28.2],[24.4,26.7],[17.1,27.6],[15.0,26.9],[14.3,24.8],[15.3,22.3],[20.3,14.5],[29.4,8.5]]]],["#f28975","#f5867b",[[[14.6,75.1],[19.1,75.1],[24.1,77.1],[40.5,86.2],[44.4,89.4],[46.3,95.8],[37.9,94.7],[29.4,91.5],[23.3,88.4],[15.9,82.9],[11.5,76.7]]]],["#f8a386","#f59480",[[[52.7,5.1],[62.0,6.6],[72.1,10.5],[80.6,15.9],[86.4,21.8],[87.2,22.9],[87.2,24.8],[86.2,25.7],[82.7,26.6],[79.7,26.1],[70.9,22.1],[56.1,12.5]]]],["#4c1740","#4e1745",[[[77.2,65.6],[80.2,65.1],[84.1,65.9],[86.4,68.3],[86.5,71.4],[84.9,73.3],[80.2,74.4],[72.1,74.4],[67.1,73.6],[65.3,72.6],[65.6,71.4],[69.9,68.8]],[[91.0,73.4],[91.5,75.2],[89.9,77.2],[89.5,75.6]]]],["#47193c","#461844",[[[10.6,23.3],[10.8,24.8],[9.0,27.7],[8.5,25.9],[9.6,23.6]],[[19.1,27.2],[24.4,26.7],[33.6,28.1],[34.9,28.9],[27.9,33.7],[23.8,35.4],[19.8,36.0],[16.6,35.7],[14.0,33.7],[13.3,32.1],[13.5,29.7],[14.8,28.6]]]],["#bab9b5","#c0bbc6",[[[92.4,36.7],[93.9,37.5],[94.7,39.5],[94.2,40.7],[92.7,41.5],[83.2,40.0],[81.2,38.4],[83.4,36.9],[88.4,36.0]]]],["#8f7c95","#94828c",[[[6.1,60.3],[15.6,61.1],[18.6,63.0],[16.8,64.5],[12.8,65.1],[7.3,64.8],[5.3,63.3],[5.3,61.1]]]],["#9d4a5a","#a0505d",[[[66.6,50.5],[68.6,50.0],[70.6,50.7],[68.6,51.2]]]]],
"9": [["#fbb3a5","#fcc8ba",[[[7.6,43.2],[8.6,42.9],[20.9,45.3],[31.4,46.5],[56.6,46.8],[58.3,47.5],[60.6,49.8],[61.6,53.5],[61.1,57.6],[59.8,59.8],[57.8,61.3],[52.3,62.8],[20.9,62.8],[13.5,61.3],[12.5,61.6],[13.0,62.6],[17.3,65.4],[11.6,69.8],[7.6,61.0],[7.0,57.0],[7.0,45.3]]]],["#9fa5ad","#adbabe",[[[60.8,34.7],[62.5,34.2],[64.3,34.9],[71.3,40.4],[88.4,47.7],[91.0,49.7],[93.0,52.3],[93.2,56.0],[89.4,59.1],[80.4,61.8],[74.4,62.8],[59.3,63.0],[58.6,62.3],[61.1,57.6],[61.6,54.7],[60.5,48.7],[61.5,47.5],[65.3,46.7],[67.6,45.3],[58.8,41.2],[58.6,37.7]]]],["#878294","#969aa6",[[[22.1,15.0],[21.3,16.6],[19.6,17.6]],[[28.2,19.3],[42.5,23.8],[65.3,27.7],[64.0,34.2],[61.3,34.4],[59.8,35.4],[58.6,37.7],[58.8,41.2],[61.6,42.7],[61.5,43.2],[58.5,43.9],[54.7,42.5],[48.7,42.0],[35.5,38.9],[31.7,37.2],[30.7,35.7],[31.2,30.4],[30.1,28.1],[27.7,25.7],[26.4,22.4],[26.7,20.3]],[[65.4,44.7],[67.8,45.3],[66.1,45.5]]]],["#80768c","#90919e",[[[19.9,65.9],[35.5,70.3],[48.2,72.8],[49.2,73.8],[50.2,80.2],[49.8,83.1],[48.7,83.7],[51.8,85.4],[58.6,86.4],[59.1,87.4],[55.8,88.4],[51.5,88.0],[47.0,85.9],[46.0,82.9],[41.9,84.9],[34.4,84.6],[34.6,83.1],[33.9,82.4],[27.4,80.7],[17.8,76.4],[13.6,73.6],[11.5,70.8],[16.3,67.4]],[[24.2,84.2],[25.1,85.1],[24.2,85.1]]]],["#fad5c5","#fcdfd2",[[[65.8,28.6],[81.6,30.1],[87.0,29.4],[90.2,30.7],[93.5,39.0],[94.2,43.0],[93.7,52.0],[86.9,46.8],[71.3,40.4],[67.1,37.5],[65.1,34.9],[64.3,32.2],[64.6,29.7]]]],["#ffdcca","#fce4c8",[[[35.4,7.5],[47.7,7.0],[56.3,8.8],[60.3,10.6],[61.8,12.6],[61.8,15.6],[60.8,16.6],[58.1,17.4],[34.9,17.4],[24.4,15.4],[24.3,14.6],[25.7,13.0]]]],["#fbd7c8","#ffe8d4",[[[58.6,75.2],[60.6,74.8],[66.3,75.6],[82.9,75.1],[84.1,75.6],[84.4,76.6],[82.9,79.4],[75.4,85.9],[71.8,88.0],[67.6,89.0],[56.6,81.7],[56.3,78.4],[57.0,76.7]]]],["#7b7086","#807d8f",[[[16.3,20.8],[16.6,22.6],[22.9,20.6],[25.7,21.1],[27.7,25.7],[30.1,28.1],[31.2,30.4],[31.1,33.9],[30.2,36.0],[27.6,36.4],[22.4,34.6],[18.6,32.6],[14.8,29.4],[13.8,28.1],[13.5,25.1],[15.0,21.9]]]],["#999ca8","#a3a4b2",[[[50.5,74.4],[52.7,74.1],[55.8,75.2],[55.5,78.6],[56.6,81.7],[64.3,86.9],[65.4,89.4],[65.0,90.5],[61.8,92.0],[55.8,93.0],[44.5,92.5],[51.5,88.7],[57.8,88.0],[59.3,87.0],[58.0,86.2],[51.0,85.0],[49.8,83.2],[48.7,82.7],[50.2,80.4],[49.3,77.1]]]],["#ed8986","#ef8980",[[[8.3,41.4],[10.5,40.7],[22.1,40.7],[51.5,45.0],[53.2,46.0],[51.2,46.5],[31.4,46.5],[11.0,43.7],[8.6,42.5]],[[6.3,45.7],[7.0,47.7],[6.5,53.2],[5.8,51.2]]]],["#f4af9e","#f6d7bc",[[[26.7,84.6],[29.1,83.7],[45.7,85.7],[48.2,86.7],[49.3,88.4],[48.5,90.4],[46.2,91.5],[39.5,91.9],[35.5,91.2],[31.4,89.5],[27.2,86.7],[26.4,85.5]]]],["#978691","#857c93",[[[58.5,6.3],[60.1,6.1],[66.6,7.8],[69.8,9.3],[73.6,12.5],[74.1,14.0],[73.6,15.4],[72.4,16.6],[68.9,17.8],[64.0,18.6],[59.6,18.1],[62.1,15.6],[62.3,13.3],[61.0,11.1],[57.5,9.1]]]],["#eb9089","#b191a2",[[[14.1,62.3],[15.9,62.0],[20.9,62.8],[52.3,62.8],[56.1,62.3],[57.1,62.8],[54.7,64.0],[27.9,64.0],[18.8,65.4],[15.1,64.0]],[[15.4,66.9],[16.1,66.9],[15.6,67.9],[13.6,68.6]]]],["#eda09c","#f3b9a0",[[[63.3,71.4],[66.3,70.9],[75.6,72.1],[80.6,72.9],[82.6,74.3],[79.1,75.6],[66.3,75.6],[60.5,74.4],[61.0,72.6]]]],["#edb7b2","#c5a5a9",[[[22.4,16.1],[34.9,17.4],[54.7,17.4],[56.6,18.1],[54.7,18.6],[31.4,18.6],[26.7,19.1],[20.1,21.3],[17.4,21.3],[18.3,19.8],[20.8,19.1],[20.9,17.1]]]],["#f08f8a","#e48a8e",[[[68.1,26.2],[70.9,25.6],[76.7,25.6],[86.5,27.4],[89.7,29.2],[81.6,30.1],[72.1,29.1],[67.8,27.9],[67.4,26.9]]]]],
"10": [["#fbc2b4","#fccec0",[[[43.2,5.3],[45.3,4.7],[56.6,5.1],[52.2,9.1],[51.2,12.8],[51.2,16.3],[53.0,24.9],[55.3,33.1],[61.5,49.0],[61.0,52.8],[54.2,71.6],[52.3,80.2],[52.3,87.2],[53.3,90.9],[57.8,93.5],[55.8,94.2],[45.3,94.2],[43.2,93.4],[46.8,89.9],[48.3,85.5],[46.0,71.4],[38.7,50.8],[39.2,46.2],[45.8,27.2],[47.7,17.4],[47.2,11.0]]]],["#f79880","#fbc59a",[[[88.2,26.6],[89.5,27.9],[93.5,39.0],[95.2,49.0],[93.4,60.8],[89.5,70.9],[86.0,76.7],[81.7,81.7],[78.1,83.2],[76.2,81.9],[75.6,79.1],[76.4,69.4],[78.6,61.1],[87.7,35.4]]]],["#9fa8ad","#aebcc1",[[[58.3,5.5],[64.0,7.0],[67.8,10.1],[70.3,14.6],[70.9,18.6],[69.1,30.7],[62.3,48.5],[59.6,43.9],[55.3,33.1],[51.2,16.3],[51.2,12.8],[52.2,9.1],[54.5,6.8]]]],["#786f85","#8b8795",[[[37.5,51.3],[38.7,52.0],[46.0,71.4],[48.3,83.1],[48.2,86.5],[46.8,89.9],[43.9,92.7],[41.5,93.5],[39.0,93.5],[32.9,90.4],[30.6,86.9],[29.1,81.4],[29.1,77.9],[30.9,68.1]]]],["#f68876","#f78776",[[[62.0,51.3],[63.1,52.0],[70.3,71.6],[70.9,82.6],[69.8,87.2],[67.8,89.9],[65.1,91.9],[61.8,93.2],[57.8,93.4],[54.5,92.0],[53.3,90.9],[52.3,87.2],[52.3,80.2],[54.2,71.6],[57.6,61.1]]]],["#f88776","#f78776",[[[40.9,5.5],[42.9,6.0],[46.5,9.3],[47.7,14.0],[47.7,17.4],[45.8,27.2],[43.5,34.2],[39.7,43.2],[37.9,44.4],[36.4,42.7],[31.9,32.1],[28.7,23.6],[28.1,18.8],[30.2,11.6],[32.2,9.0],[34.9,7.0]]]],["#fed3ad","#f9a787",[[[16.5,21.4],[16.5,22.3],[15.6,22.3]],[[14.6,24.1],[16.6,27.6],[17.9,34.6],[19.1,30.6],[19.4,30.9],[20.6,39.2],[13.3,61.0],[11.3,70.3],[10.6,70.9],[9.3,69.8],[5.6,59.5],[4.7,53.5],[4.7,44.2],[6.5,35.5],[8.1,31.4],[12.1,24.9]],[[21.4,28.2],[22.1,30.2],[21.6,34.6],[20.9,32.6]]]],["#995673","#88425d",[[[76.4,15.9],[78.6,15.6],[82.9,18.3],[88.5,25.6],[87.7,35.4],[84.1,45.7],[83.1,46.7],[81.2,45.5],[76.4,30.6],[74.6,20.8],[74.9,17.9]]]],["#88445e","#722652",[[[16.9,52.5],[18.1,52.8],[19.3,55.1],[23.3,72.1],[23.3,80.6],[20.8,82.1],[18.4,81.6],[13.5,77.2],[11.6,73.8],[11.3,71.4],[12.5,63.6],[16.1,53.3]]]],["#f6a181","#f08e7d",[[[20.4,15.8],[23.1,16.4],[24.3,20.8],[22.9,29.6],[22.6,29.9],[21.4,28.2],[20.4,34.6],[19.1,30.6],[17.9,34.6],[15.9,25.9],[16.3,21.8],[14.1,22.4],[14.0,21.8],[15.9,19.8],[17.9,19.6],[18.6,17.1]]]],["#e88281","#e99e91",[[[30.2,27.6],[30.9,29.9],[30.1,29.2]],[[33.1,36.4],[34.1,36.9],[36.4,42.7],[38.4,45.3],[38.9,47.3],[38.0,48.7],[35.2,43.9],[33.2,38.9]]]]],
"11": [["#fcc19c","#f9937e",[[[79.6,26.1],[85.7,25.9],[87.9,27.2],[89.2,29.4],[92.4,36.7],[93.2,40.5],[94.2,46.5],[93.7,53.2],[87.7,49.5],[80.2,48.8],[71.6,50.7],[61.0,55.1],[53.8,57.3],[48.8,58.1],[36.0,58.1],[25.2,56.1],[17.3,53.7],[9.3,50.0],[7.3,48.5],[6.1,46.2],[6.3,44.7],[8.0,43.5],[15.8,47.0],[19.8,47.7],[31.4,47.7],[40.0,45.8],[58.1,38.4],[68.6,31.4]]]],["#baa4ae","#ac91a2",[[[16.1,76.6],[21.6,79.6],[31.4,81.4],[46.0,79.7],[65.1,81.4],[75.9,79.4],[81.7,77.4],[82.7,77.7],[82.9,78.6],[81.7,80.6],[73.3,87.2],[67.1,90.4],[62.0,92.2],[48.8,94.2],[38.0,92.2],[29.4,89.2],[19.4,81.7],[16.3,77.9]]]],["#7f3557","#6f204c",[[[77.2,49.3],[83.7,48.8],[87.7,49.5],[91.5,51.5],[93.0,53.5],[93.5,55.5],[87.2,61.6],[78.4,65.6],[74.4,66.3],[66.3,66.3],[56.5,64.5],[45.7,60.1],[44.4,59.0],[57.5,56.3],[71.6,50.7]]]],["#9d5a73","#8e4766",[[[17.9,35.4],[29.1,34.9],[55.5,39.0],[43.5,44.7],[31.4,47.7],[19.8,47.7],[15.8,47.0],[8.6,43.7],[6.6,41.7],[6.8,40.5],[9.1,38.2],[12.3,36.7]]]],["#fcdcc1","#fedbc7",[[[41.2,6.3],[55.8,5.8],[60.8,6.6],[65.9,8.5],[72.1,11.6],[73.4,13.0],[66.9,13.5],[53.0,19.3],[50.3,19.4],[44.7,18.1],[27.9,11.8],[34.1,8.5]]]],["#8c8799","#8d8598",[[[14.6,72.8],[17.4,72.1],[24.4,72.1],[29.4,72.9],[36.5,75.1],[44.0,78.1],[45.3,79.2],[44.0,80.1],[34.9,81.4],[25.4,80.4],[19.9,78.9],[14.0,75.2],[13.8,73.6]]]],["#793259","#6c2350",[[[71.4,72.6],[74.4,72.1],[82.7,72.4],[85.0,73.4],[85.5,75.1],[84.7,76.6],[83.2,77.2],[75.9,79.4],[65.1,81.4],[53.7,80.1],[52.2,79.1],[54.3,77.6]]]],["#f4a58f","#f09086",[[[73.1,12.5],[76.4,14.3],[77.4,16.4],[76.6,18.4],[72.6,20.3],[68.6,20.9],[57.0,20.9],[54.5,19.8],[56.1,17.8],[63.5,14.6]]]],["#7a6a84","#8c8294",[[[26.6,12.6],[33.1,13.5],[43.9,17.8],[46.5,19.9],[44.2,20.9],[31.4,20.9],[27.4,20.3],[23.4,18.4],[22.4,16.3],[23.1,14.1]]]]],
"12": [["#f78776","#f58878",[[[60.8,17.9],[64.0,17.4],[76.9,19.6],[83.7,22.1],[88.4,27.9],[89.2,30.6],[88.5,33.9],[84.9,37.2],[78.7,39.2],[51.2,36.0],[46.8,34.9],[46.8,34.2],[48.5,33.4],[77.2,27.2],[79.2,25.6],[78.2,24.1],[62.3,19.1]],[[40.0,35.4],[42.7,35.2],[63.6,43.7],[57.3,45.7],[47.3,47.3],[19.3,54.2],[15.9,55.5],[13.8,57.3],[10.1,55.0],[7.0,51.2],[6.8,47.5],[13.0,43.2],[25.1,39.0]]]],["#471646","#441845",[[[61.0,44.7],[64.0,44.2],[68.1,44.7],[81.7,49.7],[82.7,51.2],[80.6,52.7],[72.4,55.0],[33.7,64.0],[30.4,63.3],[29.9,61.0],[26.1,60.0],[21.8,60.8],[16.3,58.1],[15.1,56.8],[15.9,55.5],[22.9,53.2]],[[20.1,65.6],[22.8,65.6],[24.3,66.8],[21.8,66.6]]]],["#aaa7b0","#adbbc0",[[[78.2,40.2],[86.5,41.4],[90.4,43.0],[93.5,46.2],[87.0,51.2],[87.2,52.3],[91.4,56.3],[92.2,58.3],[91.5,60.1],[86.9,63.6],[78.4,66.8],[70.1,68.9],[57.3,70.6],[43.0,63.1],[43.0,62.5],[44.4,61.8],[51.7,61.3],[55.3,58.8],[81.4,52.3],[82.7,51.2],[81.7,49.7],[66.6,43.7],[68.3,42.7]]]],["#786d84","#8d8b9b",[[[46.8,61.0],[50.0,60.5],[52.0,61.1],[48.8,61.6]],[[39.9,62.3],[53.7,68.4],[55.5,70.1],[55.6,71.4],[31.1,76.4],[21.4,79.2],[21.1,80.4],[26.2,82.7],[26.4,83.2],[25.4,83.6],[20.1,82.2],[16.6,79.9],[15.1,77.9],[14.5,74.6],[15.9,71.8],[23.9,67.3],[24.8,65.6],[32.4,66.1],[33.4,65.8],[32.9,64.5]]]],["#a2667a","#8c4764",[[[12.1,26.7],[13.1,26.1],[20.6,26.1],[22.9,26.7],[23.1,28.1],[19.3,29.7],[18.6,30.9],[22.1,33.7],[27.6,36.4],[28.7,37.9],[22.3,39.9],[20.3,38.7],[13.6,37.5],[10.3,36.2],[9.1,35.0],[8.8,32.9],[10.8,28.2]]]],["#995b76","#914a60",[[[43.4,81.9],[45.2,81.6],[49.7,84.1],[58.6,86.7],[60.1,87.9],[45.3,90.7],[38.0,91.5],[35.9,90.9],[35.4,89.7],[36.0,88.4],[43.9,84.6],[44.4,83.7]],[[56.0,82.1],[59.3,81.4],[64.3,82.2],[65.9,83.2],[64.3,84.1],[60.1,84.1],[56.5,83.1]],[[61.8,91.5],[62.8,92.0],[61.5,92.9],[57.3,92.5]]]],["#965572","#8e4e6c",[[[33.6,10.1],[33.9,10.5],[33.1,11.0],[29.2,12.6],[29.4,14.8],[33.6,16.4],[39.4,16.9],[40.5,19.9],[34.7,24.3],[20.9,24.4],[18.9,23.9],[20.6,22.8],[20.1,20.9],[26.2,18.4],[26.2,17.6],[24.1,15.8],[25.1,13.5],[29.6,11.0]]]],["#ffcba9","#f1ad95",[[[6.3,51.5],[7.5,51.8],[10.1,55.0],[14.3,57.8],[32.7,65.0],[33.4,65.8],[31.4,66.3],[22.1,65.1],[12.1,63.5],[9.6,62.5],[6.5,58.6],[5.8,54.7]]]],["#ffb3a2","#fcc9be",[[[45.5,35.5],[64.0,37.2],[75.1,38.9],[76.6,39.9],[70.3,42.4],[64.0,43.0],[61.0,42.5],[46.7,37.0]]]],["#f4b2aa","#ee9290",[[[49.2,83.1],[52.3,82.6],[65.4,84.6],[69.4,86.4],[69.8,88.7],[67.4,90.7],[64.3,91.4],[64.0,89.7],[62.8,88.4],[50.5,84.4],[49.2,83.7]]]],["#d8ecea","#d9d6e7",[[[92.2,47.5],[93.2,47.8],[94.0,50.2],[93.4,55.0],[92.2,56.8],[87.7,53.0],[87.0,51.7],[87.5,50.3]]]],["#7b6585","#806489",[[[49.3,6.3],[51.2,6.8],[48.0,8.5],[38.2,10.3],[35.9,9.3],[37.4,8.3]],[[29.1,12.6],[31.2,15.6],[29.4,14.8]]]]]
}
+28
View File
@@ -0,0 +1,28 @@
# 色带生成器
此目录可以独立使用。Python 依赖为 NumPy 和 Pillow。运行以下命令生成一枚五圈的窄带螺旋:
```sh
python3 generate.py --layout spiral --faces 5 --width .35 --continuity .94 --twist 38 --tilt -20 --palette '#ff967e' '#f9d2b0' '#b5c5c5' --background '#461646' --size 512 --output spiral.png
```
| 参数 | 含义 |
| --- | --- |
| `--layout` | `rings` 为球面纬带,`spiral` 为绕球的一条螺旋,`petals` 为绕中心分布的瓣 |
| `--faces` | 1 至 16,分别表示纬带数、螺旋圈数或瓣数;投影后可见的色块还受遮挡影响 |
| `--continuity` | 0 至 1,沿带长保留的范围。0 为纯背景,1 取消沿长度方向的裁切 |
| `--width` | 大于 0 且不超过 1,控制纬带及螺旋的相对宽度,或花瓣从外缘向内延伸的深度 |
| `--twist` | 扭转角度,正负改变形变方向 |
| `--tilt` | 整枚图形在画面内的旋转角度 |
| `--palette` | 一个或多个十六进制基色。环与瓣依序循环使用,螺旋沿带长平滑换色 |
| `--background` | 背景色,也参与背面色的计算 |
`--size` 控制单枚图像的像素尺寸,`--output` 指定 PNG 输出路径。相同参数可重复得到相同图形。
```sh
python3 generate.py --study --size 124 --output study.png
```
参数对照图前三行分别只改面数(2、3、4、6)、连续性(0.28、0.52、0.76、1)、扭转角(−55°、−15°、25°、65°)。第四行依次展示纬带、螺旋、四瓣及三瓣组合。
每个像素沿视线与单位球壳相交两次。生成器在两个交点分别计算色带的覆盖情况,再根据基色、面内渐变和背景色绘制正面、背面与重叠部分。图形完全由参数生成。
+183
View File
@@ -0,0 +1,183 @@
"""Generate ribbon fields with NumPy and Pillow. Run --help for the design controls."""
import argparse
from dataclasses import dataclass, replace
from pathlib import Path
import numpy as np
from PIL import Image, ImageColor
HERE = Path(__file__).resolve().parent
@dataclass(frozen=True)
class Design:
layout: str = "spiral"
faces: int = 4
continuity: float = .88
width: float = .46
twist: float = 24
tilt: float = -14
palette: tuple = ("#ff967e", "#f9d2b0", "#b5c5c5")
background: str = "#461646"
def rgb(code):
if len(code) != 7 or not code.startswith("#"):
raise ValueError("colours must use #RRGGBB")
return np.array(ImageColor.getrgb(code), dtype=float)
def check(d):
if d.layout not in ("rings", "spiral", "petals"):
raise ValueError("layout must be rings, spiral or petals")
if not 1 <= d.faces <= 16:
raise ValueError("faces must be 1..16")
if not 0 <= d.continuity <= 1 or not 0 < d.width <= 1:
raise ValueError("continuity must be 0..1 and width must be greater than 0 and at most 1")
if not np.isfinite([d.twist, d.tilt]).all():
raise ValueError("angles must be finite")
if not d.palette:
raise ValueError("supply at least one base colour")
def mix(a, b, weight):
return a + (b-a)*weight
def coverage(along, continuity):
"""Angular half-length of a round-ended arc; 1 closes the whole loop."""
if continuity == 1:
return np.ones_like(along)
distance = np.abs((along + np.pi) % (2*np.pi) - np.pi) / np.pi
shoulder = min(.12, continuity)
inside = np.clip((continuity-distance)/max(shoulder, 1e-8), 0, 1)
return np.sqrt(inside*(2-inside))
def face(d, x, y, z, palette):
angle = np.deg2rad(d.twist)
if d.layout == "petals":
# Radial sectors on the shell. Opposite depths shear the two sides
# of each petal in opposite directions and create the crossing.
frequency = d.faces/(2*np.pi)
turn = np.arctan2(x, y)
radius = np.hypot(x,y)
best = np.full_like(x,-np.inf)
index = np.zeros_like(x,dtype=int)
along = np.zeros_like(x)
for sector in range(d.faces):
orientation = sector/frequency
delta = (turn-orientation+np.pi)%(2*np.pi)-np.pi
# Scale each cap with angular spacing so higher face counts
# still leave a legible opening between neighbouring lobes.
half_span = min(np.pi/2, np.pi/d.faces)
depth = (1-np.cos(half_span))*d.width
local = np.clip(delta/max(d.continuity,1e-8), -np.pi, np.pi)
folded = radius*(np.cos(local)+np.sin(angle)*1.45*z*np.sin(local))
score = folded-1+depth
active = score > best
index = np.where(active,sector,index)
along = np.where(active,np.sin(delta),along)
best = np.maximum(best,score)
visible = (best > 0) & (d.continuity > 0)
else:
# Rotate latitude circles by a longitude-dependent angle. This
# deformation stays on the unit sphere for either sign of depth.
bend = angle*x
v = y*np.cos(bend) + z*np.sin(bend)
w = z*np.cos(bend) - y*np.sin(bend)
longitude = np.arctan2(w, x)
latitude = np.arcsin(np.clip(v,-1,1))/np.pi+.5
phase = latitude*d.faces-.5
if d.layout == "spiral":
phase -= longitude/(2*np.pi)
index = np.floor(phase+.5).astype(int)
along = np.sin(longitude)
# Spiral sectors use a periodic cut at the same meridian every turn.
# Separate rings can stagger their cuts without a seam.
offset = 0 if d.layout == "spiral" else index*2.39996
taper = coverage(longitude+offset, d.continuity)
visible = (np.abs(phase-index) < .5*d.width*taper) & (taper > 0)
if d.layout == "spiral":
# Vary pigment continuously with latitude, including across the seam
# where the spiral's integer winding number changes.
pigment = latitude*d.faces
band = np.floor(pigment).astype(int)
f = pigment-band
f = f*f*(3-2*f)
color = mix(palette[band%len(palette)], palette[(band+1)%len(palette)], f[...,None])
else:
color = palette[index%len(palette)]
glow = np.clip(.09-.13*x+.12*y+.09*along, 0, .42)
return visible, mix(color, 255., glow[...,None])
def render(d, size=256):
check(d)
if not 16 <= size <= 2048:
raise ValueError("size must be 16..2048")
palette = np.array([rgb(c) for c in d.palette])
bg = rgb(d.background)
axis = (np.arange(size*3)+.5) * 2.16/(size*3)-1.08
output = np.empty((size,size,3), dtype=np.uint8)
roll = np.deg2rad(d.tilt)
for start in range(0,size,16):
stop = min(start+16,size)
xx, yy = np.meshgrid(axis,-axis[start*3:stop*3])
x = xx*np.cos(roll) - yy*np.sin(roll)
y = xx*np.sin(roll) + yy*np.cos(roll)
radius2 = x*x+y*y
z = np.sqrt(np.maximum(0,1-radius2))
front, ink = face(d,x,y,z,palette)
back, reverse = face(d,x,y,-z,palette)
# Back faces receive less light. The same base pigments determine
# the rear and overlap colours even when the palette is changed.
rear = mix(bg,reverse,.44)
both = mix(ink,reverse,.24)
both = mix(both,255.,(.06+.18*z)[...,None])
paint = np.where(front[...,None],np.where(back[...,None],both,ink),rear)
paint = np.where(((front|back)&(radius2<=1))[...,None],paint,bg)
block = paint.reshape(stop-start,3,size,3,3).mean(axis=(1,3))
output[start:stop] = np.rint(block).astype(np.uint8)
return Image.fromarray(output)
def study(d, size):
# The first three rows isolate one control; the last shows layout examples.
rows = [("faces",(2,3,4,6)), ("continuity",(.28,.52,.76,1)),
("twist",(-55,-15,25,65)), ("layout",("rings","spiral","petals","petals"))]
gap = max(6, size//6)
cell = size+gap
canvas = Image.new("RGB",(4*cell+gap,4*cell+gap),d.background)
for row,(key,values) in enumerate(rows):
for col,value in enumerate(values):
variant = replace(d,**{key:value})
if row==3 and col==3:
variant = replace(variant,faces=3, width=.65, twist=38, tilt=0, continuity=1)
canvas.paste(render(variant,size),(gap+col*cell,gap+row*cell))
return canvas
if __name__ == "__main__":
defaults = Design()
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--layout", choices=("rings","spiral","petals"), default=defaults.layout)
parser.add_argument("--faces",type=int,default=defaults.faces,help="rings, spiral turns or petals (1..16)")
parser.add_argument("--continuity",type=float,default=defaults.continuity,help="arc coverage (0..1)")
parser.add_argument("--width",type=float,default=defaults.width,help="fraction of spacing filled (0..1]")
parser.add_argument("--twist",type=float,default=defaults.twist,help="spherical deformation in degrees")
parser.add_argument("--tilt",type=float,default=defaults.tilt,help="image-plane rotation in degrees")
parser.add_argument("--palette",nargs="+",default=defaults.palette,help="one or more #RRGGBB colours")
parser.add_argument("--background",default=defaults.background,help="#RRGGBB")
parser.add_argument("--size",type=int,default=256)
parser.add_argument("--output",required=True,type=Path)
parser.add_argument("--study",action="store_true",help="render a 4 by 4 parameter comparison")
args = parser.parse_args()
design = Design(**{key:getattr(args,key) for key in Design.__dataclass_fields__})
try:
if not 16 <= args.size <= 2048:
raise ValueError("size must be 16..2048")
img = study(design,args.size) if args.study else render(design,args.size)
except ValueError as error:
parser.error(str(error))
img.save(args.output)
Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

+82
View File
@@ -0,0 +1,82 @@
"""Render a ribbon study as editable SVG, using only the standard library."""
from math import cos, sin, pi
from pathlib import Path
BACKGROUND = "#431744"
# Coordinates are relative to the centre of the reference mark.
CAP = "M-91 -78 C-67 -111 -34 -121 0 -121 C33 -121 70 -107 90 -80 C105 -59 82 -52 63 -53 C37 -52 14 -63 0 -74 C-23 -58 -47 -52 -69 -53 C-91 -53 -100 -63 -91 -78Z"
LEFT = "M-91 -78 C-58 -107 -28 -99 0 -74 C-23 -58 -47 -52 -69 -53 C-91 -53 -100 -63 -91 -78Z"
RIGHT = "M0 -74 C37 -104 65 -98 90 -80 C105 -59 82 -52 63 -53 C37 -52 14 -63 0 -74Z"
def gradient(name, colors):
stops = ''.join(f'<stop offset="{i/(len(colors)-1):.2f}" stop-color="{color}"/>'
for i, color in enumerate(colors))
return f'<linearGradient id="{name}" x2="100%" y2="24%">{stops}</linearGradient>'
def trefoil():
layers = []
palettes = [
("#d6c9c6", "#917687", "#a35c78", "#874969", "#99909d", "#766d82"),
("#ffe0bf", "#ffc0a2", "#8e8e9b", "#726d84", "#ffb295", "#ff8c76"),
("#ffb390", "#ff917c", "#ff9983", "#ff846f", "#b57184", "#8c506f"),
]
for index, colors in enumerate(palettes):
parts = []
for face, outline in enumerate((CAP, LEFT, RIGHT)):
name = f"petal-{index}-{face}"
parts.append(gradient(name, colors[2*face:2*face+2]))
parts.append(f'<path fill="url(#{name})" d="{outline}"/>')
layers.append(f'<g transform="rotate({120*index})">{"".join(parts)}</g>')
return ''.join(layers)
def coil(turns, width, pitch, tilt, prefix):
"""Project a spherical helix. Draw its far half-turns before its near ones."""
palettes = [
[("#7b566f", "#aa7889"), ("#a4b4bb", "#79748c"), ("#834764", "#b77987")],
[("#ffa58a", "#ff8876"), ("#ffdebb", "#f2b9a8"), ("#c2d6d0", "#a39daa")],
]
layers = [[], []]
for half in range(2 * turns):
near = half % 2
start = half*pi
name = f"{prefix}-{half}"
def point(t, side):
u = t / (2*pi*turns)
lat = -pi/2 + pi*u + side*width*pi/(2*turns)*sin(pi*u)**.55
lat += pitch*sin(t)*cos(lat) + .12*sin(2*t)*cos(lat)
return f"{100*cos(lat)*cos(t):.2f},{-100*sin(lat):.2f}"
# Follow the actual circular limb between both edges at each turn.
points = [point(start + pi*j/80, -1) for j in range(81)]
points += [point(start + pi, -1+j/8) for j in range(1,17)]
points += [point(start + pi*j/80, 1) for j in reversed(range(80))]
points += [point(start, 1-j/8) for j in range(1,17)]
layers[near].append(gradient(name, palettes[near][(half//2)%3]))
opacity = .90 if near else .84
layers[near].append(f'<polygon opacity="{opacity}" points="{" ".join(points)}" fill="url(#{name})"/>')
return f'<g transform="rotate({tilt})">{"".join(layers[0]+layers[1])}</g>'
def place(shape, x, y, scale):
return f'<g transform="translate({x} {y}) scale({scale})">{shape}</g>'
def draw():
marks = [place(trefoil(), 214, 238, 1.20)]
for index, (x, y, turns, width, pitch, tilt) in enumerate([
(502, 88, 2, .77, .45, -14), (673, 88, 3, .91, .40, 46),
(502, 239, 4, .85, .21, 4), (673, 239, 4, .46, .10, -10),
(502, 391, 3, .65, .39, -12), (673, 391, 3, .82, .21, 82),
]):
marks.append(place(coil(turns, width, pitch, tilt, f"s{index}"), x, y, .48))
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 480" width="800" height="480">'
f'<title>Bedrock ribbon studies</title><rect width="800" height="480" fill="{BACKGROUND}"/>'
+ ''.join(marks) + '</svg>\n')
if __name__ == "__main__":
Path(__file__).with_name("preview.svg").write_text(draw(), encoding="utf-8")
+116
View File
@@ -0,0 +1,116 @@
"""Fit a gradient mesh to the 750 x 1500 reference sheet. Requires NumPy and Pillow."""
import argparse
import json
from pathlib import Path
import numpy as np
from PIL import Image
from render import HERE, render
# Centre, half-width of square, transpose to cut across vertical ribbons.
CROPS = [(459,255,40,1), (300,1108,40,1), (451,1108,41,0), (609,128,40,1),
(148,1245,42,1), (459,128,41,1), (221,256,122,0), (604,1245,41,1),
(148,1383,41,1), (609,382,41,0), (459,382,41,1), (609,255,41,1)]
def simplify(values, tolerance):
"""Indices of knots in a piecewise linear approximation with bounded error."""
keep = [0, len(values)-1]
pending = [(0, len(values)-1)]
while pending:
a, b = pending.pop()
if b-a < 2:
continue
t = np.arange(1, b-a)[:, None]/(b-a)
error = np.max(np.abs(values[a+1:b] - (values[a]+t*(values[b]-values[a]))), axis=1)
split = int(np.argmax(error))
if error[split] > tolerance:
mid = a+1+split
keep.append(mid)
pending.extend([(a,mid), (mid,b)])
return sorted(keep)
def align(a, b, spacing):
"""Monotone matching along two cross-sections, penalising stretch and drift."""
n = len(a)
pos = np.arange(n)
displacement = np.abs(pos[:, None]-pos)
cost = (np.mean(np.abs(a[:, None]-b), axis=2) + .5*displacement
+ 5*np.maximum(displacement-2*spacing, 0))
total = np.full((n+1, n+1), np.inf)
total[0,0] = 0
# All entries on one antidiagonal can be updated together.
for k in range(2, 2*n+1):
x = np.arange(max(1,k-n), min(n,k-1)+1)
y = k-x
total[x,y] = cost[x-1,y-1]+np.minimum(total[x-1,y-1],
1.8+np.minimum(total[x-1,y],total[x,y-1]))
x = y = n
path = []
while x and y:
path.append((x-1,y-1))
step = np.argmin([total[x-1,y-1], total[x-1,y]+1.8, total[x,y-1]+1.8])
x -= int(step != 2)
y -= int(step != 1)
points = np.array(path[::-1])
return points[simplify(points, .8)].tolist()
def fit(rgb, transpose):
data = (rgb.swapaxes(0,1) if transpose else rgb).astype(float)
n = len(data)
sample = np.arange(n)
sections, matches = {}, {}
def profile(y):
if y not in sections:
knots = simplify(data[y], 5)
sections[y] = np.column_stack((sample[knots], data[y,knots])).astype(int).tolist()
return sections[y]
def match(a,b):
if (a,b) not in matches:
matches[a,b] = align(data[a],data[b],b-a)
return matches[a,b]
def build(cuts):
return dict(span=n, transpose=bool(transpose), cuts=cuts, sections=[profile(y) for y in cuts],
correspondence=[match(a,b) for a,b in zip(cuts,cuts[1:])])
cuts = sorted({0,n-1,*range(0,n,max(6,n//10))})
for _ in range(5):
model = build(cuts)
view = np.asarray(render(model, n))
if transpose:
view = view.swapaxes(0,1)
delta = np.mean(np.abs(view-data),axis=2)
# Include a high percentile so a narrow tip cannot disappear in the mean.
errors = delta.mean(axis=1) + .35*np.percentile(delta,95,axis=1)
additions = []
for a,b in zip(cuts,cuts[1:]):
if b-a<2:
continue
y = a+1+int(np.argmax(errors[a+1:b]))
if errors[y] > (10 if b-a <= 3 else 5):
additions.append(y)
if not additions:
break
cuts = sorted(cuts+additions)
return build(cuts)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("reference", type=Path)
args = parser.parse_args()
photo = Image.open(args.reference).convert("RGB")
if photo.size != (750,1500):
parser.error("Expected the original 750 x 1500 reference sheet")
models = []
for cx,cy,r,transpose in CROPS:
crop = np.asarray(photo.crop((cx-r,cy-r,cx+r,cy+r)))
models.append(fit(crop, transpose))
(HERE/"marks.json").write_text("[\n"+",\n".join(json.dumps(model,separators=(",",":"))
for model in models)+"\n]\n")
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

@@ -0,0 +1,56 @@
"""Render fitted ribbon cross-sections. Requires NumPy and Pillow."""
import argparse
import json
from pathlib import Path
import numpy as np
from PIL import Image
HERE = Path(__file__).resolve().parent
def section(section_data, v):
knots = np.array(section_data, dtype=float)
return np.stack([np.interp(v, knots[:, 0], channel) for channel in knots[:, 1:].T], axis=-1)
def render(model, size):
"""Interpolate geometry first, then interpolate the colours on each face."""
n = model["span"]
axis = (np.arange(size) + .5) * n / size - .5
out = np.empty((size, size, 3), dtype=np.uint8)
cuts = np.array(model["cuts"])
for row, y in enumerate(axis):
i = np.clip(np.searchsorted(cuts, y, side="right")-1, 0, len(cuts)-2)
t = np.clip((y-cuts[i])/(cuts[i+1]-cuts[i]), 0, 1)
a, b = np.array(model["correspondence"][i]).T
middle = (1-t)*a + t*b
u = np.interp(axis, middle, a)
v = np.interp(axis, middle, b)
colors = (1-t)*section(model["sections"][i], u) + t*section(model["sections"][i+1], v)
out[row] = np.clip(np.rint(colors), 0, 255)
if model["transpose"]:
out = np.swapaxes(out, 0, 1)
return Image.fromarray(out)
def sheet(models, size):
gap = size//3
canvas = Image.new("RGB", (4*(size+gap)+gap, 3*(size+gap)+gap), (70, 22, 70))
for i, model in enumerate(models):
canvas.paste(render(model, size), (gap+i%4*(size+gap), gap+i//4*(size+gap)))
return canvas
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--mark", type=int, choices=range(1, 13))
parser.add_argument("--size", type=int, default=128, help="pixels per mark")
parser.add_argument("--output", type=Path)
args = parser.parse_args()
if args.size < 1:
parser.error("--size must be positive")
models = json.loads((HERE/"marks.json").read_text())
image = render(models[args.mark-1], args.size) if args.mark else sheet(models, args.size)
target = args.output or HERE/(f"mark-{args.mark:02}.png" if args.mark else "preview.png")
image.save(target)
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 102 KiB

+417
View File
@@ -0,0 +1,417 @@
[
{
"mode": "bands",
"angles": [
0,
0,
19.7,
0
],
"bands": [
[
-0.95,
0.1905
],
[
-0.458,
0.35
],
[
0.2795,
0.3775
],
[
0.4815,
0.4985
],
[
0.87,
0.24
]
],
"inks": {
"0/1": "#eeb798",
"0/2": "#8a8396",
"0/3": "#ea8176",
"0/4": "#bc8780",
"0/5": "#826d7d",
"1/0": "#9f9fad",
"1/1": "#dbb6ad",
"2/0": "#874564",
"2/2": "#ac92a1",
"3/0": "#82798c",
"3/3": "#f3c2b6",
"3/4": "#aeb2b7",
"4/0": "#694f6e",
"4/3": "#f08679",
"4/4": "#56274a",
"4/5": "#8a8398",
"5/0": "#e7a990",
"5/4": "#f8bd93",
"5/5": "#f4cbb7"
}
},
{
"mode": "bands",
"angles": [
-1.791,
-32.186,
0.07,
-2.839
],
"bands": [
[
-1.0594,
0.4096
],
[
-0.731,
0.3594
],
[
-0.3312,
0.2787
],
[
0.1514,
0.2592
],
[
0.6196,
0.2753
],
[
1.0483,
0.4561
]
],
"inks": {
"0/3": "#784e69",
"0/4": "#8b6172",
"0/5": "#7b4861",
"0/6": "#693b58",
"1/0": "#efb092",
"1/2": "#ddaaa6",
"1/3": "#eab8a3",
"2/0": "#da7e77",
"2/2": "#713b53",
"2/3": "#d18e8c",
"2/4": "#e9a59b",
"3/0": "#e7a28a",
"3/3": "#966776",
"3/4": "#f6c4a7",
"3/5": "#f6bfa2",
"4/0": "#e88881",
"4/4": "#ae6671",
"4/5": "#e98a82",
"4/6": "#f1988c",
"5/0": "#cc938c",
"5/5": "#b57a7f",
"5/6": "#d79a8f"
}
},
{
"mode": "bands",
"angles": [
89.303,
14.637,
-1.031,
11.417
],
"bands": [
[
-0.5511,
0.5986
],
[
0.5624,
0.5718
]
],
"inks": {
"0/1": "#8b7c92",
"0/2": "#af7b7e",
"1/0": "#7f4366",
"1/1": "#9c798e",
"2/0": "#dac4b1",
"2/2": "#dcb6a7"
}
},
{
"mode": "bands",
"angles": [
-44.684,
26.855,
-1.6,
2.652
],
"bands": [
[
-0.8871,
0.3778
],
[
-0.2958,
0.4983
],
[
0.5552,
0.665
]
],
"inks": {
"0/1": "#f0b093",
"0/2": "#91909e",
"0/3": "#dca4a1",
"1/1": "#f9c09b",
"2/0": "#9ca0ab",
"2/1": "#f7ceb7",
"2/2": "#b6bcc6",
"3/0": "#794c69",
"3/2": "#b2a2ac",
"3/3": "#e69c95"
}
},
{
"mode": "bands",
"angles": [
0,
0,
24.3,
0
],
"bands": [
[
-0.69,
0.57
],
[
0.7285,
0.57
]
],
"inks": {
"0/1": "#a7afb5",
"0/2": "#80778c",
"1/0": "#ef8275",
"1/1": "#f9c7ba",
"2/0": "#94536e",
"2/2": "#b6a4ad"
}
},
{
"mode": "bands",
"angles": [
24.617,
21.92,
15.227,
4.721
],
"bands": [
[
-0.3092,
0.9832
],
[
0.6666,
0.569
]
],
"inks": {
"0/1": "#6f3d5c",
"0/2": "#868495",
"1/0": "#946176",
"1/1": "#ea9187",
"2/0": "#e4af94",
"2/1": "#f6ba9f",
"2/2": "#997b80"
}
},
{
"angles": [
0,
0,
0,
0
],
"bands": [],
"mode": "petals",
"inks": {
"0/1": "#9a556e",
"1/0": "#81798d",
"1/1": "#b8a5b0",
"0/2": "#ff9b81",
"2/0": "#837d91",
"2/2": "#ffd5b5",
"0/3": "#a55f72",
"3/0": "#ff8771",
"3/3": "#ffa188"
}
},
{
"mode": "bands",
"angles": [
-0.899,
9.985,
-3.206,
-0.452
],
"bands": [
[
-0.8721,
0.2916
],
[
0.0183,
0.5875
],
[
0.9273,
0.3999
]
],
"inks": {
"0/1": "#f68b79",
"0/2": "#9294a2",
"1/1": "#eda58f",
"2/0": "#90909f",
"2/2": "#b9c5ca",
"3/0": "#833c60",
"3/3": "#a1506f"
}
},
{
"mode": "bands",
"angles": [
7.565,
23.002,
-9.66,
12.642
],
"bands": [
[
-1.0253,
0.7238
],
[
-0.0246,
0.9293
],
[
0.8626,
0.5551
]
],
"inks": {
"0/1": "#dcbeb2",
"0/2": "#bb8d90",
"1/1": "#beadb0",
"2/0": "#5e3458",
"2/1": "#9c8791",
"2/2": "#d2b0ad",
"3/0": "#5a375a",
"3/2": "#765e78",
"3/3": "#d9bdb1"
}
},
{
"mode": "bands",
"angles": [
90.42,
1.38,
26.293,
2.256
],
"bands": [
[
-0.9005,
0.3924
],
[
0.0113,
0.5277
],
[
0.9205,
0.3849
]
],
"inks": {
"0/1": "#8f4b68",
"0/2": "#f38778",
"0/3": "#793057",
"1/0": "#f29c83",
"1/1": "#e1a78e",
"2/0": "#9897a3",
"2/2": "#f6c4b7",
"3/0": "#f39d82",
"3/3": "#edb79a"
}
},
{
"mode": "bands",
"angles": [
-8.06,
11.533,
19.651,
12.902
],
"bands": [
[
-0.8357,
0.371
],
[
0.0753,
0.4804
],
[
0.8661,
0.3363
]
],
"inks": {
"0/1": "#8d5b78",
"0/2": "#f29c85",
"0/3": "#998994",
"1/0": "#867e94",
"1/1": "#ad95a4",
"2/0": "#62224d",
"2/2": "#c4827f",
"3/0": "#864255",
"3/3": "#f7c8b2"
}
},
{
"mode": "spiral",
"angles": [
8,
3,
0,
0
],
"bands": [
[
0.12,
0.38
]
],
"inks": {
"1/0": "#ff967e",
"2/0": "#a8babb",
"3/0": "#a26d86",
"0/1": "#7c526f",
"0/2": "#98586e",
"0/3": "#714561",
"1/1": "#ffb58d",
"1/2": "#ffb58d",
"1/3": "#ffb58d",
"2/1": "#bfd2c9",
"2/2": "#bfd2c9",
"2/3": "#bfd2c9",
"3/1": "#ac8497",
"3/2": "#ac8497",
"3/3": "#ac8497"
}
}
]
Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

+93
View File
@@ -0,0 +1,93 @@
"""Procedural ribbon shells. Run with --turn 20 to rotate every shell in depth."""
import argparse
import json
from math import asin, atan2, cos, pi, radians, sin, sqrt
from pathlib import Path
import struct
import zlib
BG = (68, 23, 68)
STYLE_FILE = Path(__file__).with_name("shell-styles.json")
def make_shader(style, turn):
roll, pitch, linear, quadratic = style["angles"]
cr, sr = cos(radians(roll)), sin(radians(roll))
cp, sp = cos(radians(pitch)), sin(radians(pitch))
ct, st = cos(radians(turn)), sin(radians(turn))
bands = style["bands"]
palette = {tuple(map(int, pair.split("/"))): tuple(bytes.fromhex(ink[1:]))
for pair, ink in style["inks"].items()}
mode = style["mode"]
def band_at(u, v, w):
if mode == "petals":
for index, (a, b) in enumerate(((0, 1), (.8660254, -.5), (-.8660254, -.5)), 1):
radial, tangent = a*u+b*v, b*u-a*v
if radial + .72*w*tangent > .725:
return index
return 0
if mode == "spiral":
phase, width = bands[0]
cycle = 3*(.5+asin(max(-1, min(1, v)))/pi) - atan2(w,u)/(2*pi) + phase
return 1+round(cycle)%3 if abs(cycle-round(cycle)) < width/2 else 0
angle = radians(linear*u + quadratic*(2*u*u-1))
height = v*cos(angle) + w*sin(angle)
for index, (centre, width) in enumerate(bands, 1):
if abs(height-centre) <= width/2:
return index
return 0
def face(x, y, z):
depth = st*x+ct*z
return band_at(ct*x-st*z, cp*y+sp*depth, cp*depth-sp*y)
def pixel(x, y):
d = 1-x*x-y*y
if d <= 0:
return BG
z = sqrt(d)
u, v = cr*x+sr*y, cr*y-sr*x
front, back = face(u,v,z), face(u,v,-z)
if not (front or back):
return BG
# Each pair of visible faces defines one ink mixture. New angles can
# reveal pairs absent from the reference view.
color = palette.get((front, back))
if color is None:
ink = palette.get((front, 0), palette.get((front, front), BG))
rear = palette.get((0, back), palette.get((back, back), BG))
color = tuple((f+r)/2 for f,r in zip(ink,rear)) if front and back else (ink if front else rear)
light = 1+.045*(-x+y)/2
return tuple(min(255,round(k*light)) for k in color)
return pixel
def sheet(turn, size=118, samples=3):
gap = size//3
width, height = 4*(size+gap)+gap, 3*(size+gap)+gap
pixels = bytearray(bytes(BG)*width*height)
for i, style in enumerate(json.loads(STYLE_FILE.read_text())):
shade = make_shader(style, turn)
left, top = gap+(i%4)*(size+gap), gap+(i//4)*(size+gap)
for row in range(size):
for col in range(size):
colors = [shade(2*(col+(a+.5)/samples)/size-1,
1-2*(row+(b+.5)/samples)/size)
for a in range(samples) for b in range(samples)]
start = 3*((top+row)*width+left+col)
pixels[start:start+3] = bytes(round(sum(c)/len(colors)) for c in zip(*colors))
def chunk(kind, data):
return (struct.pack(">I", len(data))+kind+data+
struct.pack(">I", zlib.crc32(kind+data)))
scanlines = b"".join(b"\0"+pixels[i:i+3*width] for i in range(0,len(pixels),3*width))
return (b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">2I5B",width,height,8,2,0,0,0))+
chunk(b"IDAT",zlib.compress(scanlines,9))+chunk(b"IEND",b""))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--turn", type=float, default=0)
parser.add_argument("--output", type=Path, default=Path(__file__).with_suffix(".png"))
options = parser.parse_args()
options.output.write_bytes(sheet(options.turn))