Repository navigation
Expand file tree
/
Copy pathlogo.py
More file actions
146 lines (131 loc) · 6.88 KB
/
Copy pathlogo.py
File metadata and controls
146 lines (131 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os, sys
import numpy as np
import cv2
import palette, room
# usage: logo.py [out_dir]
# The Construct mark: the animation's last frame without the grid - the room in outline,
# open on the left. Same room and camera as video.py (room.py). The strokes live in a 0..100 box;
# they are written as SVG (color, GNOME symbolic, Orchis' Activities button, the installer's app
# tile) and rendered to PNG at icon sizes.
OUT = sys.argv[1] if len(sys.argv) > 1 else "logos"
os.makedirs(OUT, exist_ok=True)
PAL = palette.load()
CYAN = PAL["brand"]["cyan"]
# ---------- the room's outline (room.py), seen by the animation's camera ----------
def mark(lines3d):
"""Project 3D strokes and normalize them into the 0..100 box (aspect kept)."""
lines = [(room.project(a), room.project(b)) for a, b in lines3d]
pts = np.array([p for l in lines for p in l])
lo, hi = pts.min(0), pts.max(0)
s = 100 / (hi - lo).max()
off = (100 - (hi - lo) * s) / 2 - lo * s
return [(a * s + off, b * s + off) for a, b in lines]
LINES = mark(room.OUTLINE)
NAME = "construct"
# ---------- output ----------
def chain(segments, eps=1e-6):
"""Join segments that share endpoints into continuous strokes (polylines), so corners
are real joins instead of separate lines meeting. Returns (points, closed) pairs."""
segs = [(np.asarray(a, float), np.asarray(b, float)) for a, b in segments]
same = lambda p, q: np.linalg.norm(p - q) < eps
out = []
while segs:
a, b = segs.pop(0)
pts = [a, b]
grown = True
while grown:
grown = False
for i, (c, d) in enumerate(segs):
for (u, v) in ((c, d), (d, c)):
if same(pts[-1], u): pts.append(v)
elif same(pts[0], v): pts.insert(0, u)
else: continue
segs.pop(i); grown = True; break
if grown: break
closed = len(pts) > 2 and same(pts[0], pts[-1])
out.append((pts[:-1] if closed else pts, closed))
return out
def hex2bgr(h):
h = h.lstrip("#"); return tuple(int(h[i:i + 2], 16) for i in (4, 2, 0))
def stroke_px(size):
# Whole pixels: 1 px only at 16, where 2 would fill the mark; from 24 up two, or the line
# fades (a 1 px cyan stroke at 32 px all but vanished).
return 1 if size <= 16 else 2
def snap(lines, size):
"""Move endpoints onto the pixel grid so verticals and horizontals cover whole pixels: a
1 px line on a pixel's center, a 2 px one on the edge between two."""
off = 0.5 if stroke_px(size) % 2 else 0.0
c = lambda v: (np.floor((v + 6) * size / 112) + off) * 112 / size - 6
return [(c(np.asarray(a)), c(np.asarray(b))) for a, b in lines]
def render(lines, size, color):
"""The mark in color on a transparent background, as the SVG is: BGRA."""
ss = 8
lines = snap(lines, size)
S = size * ss
k = S / 112
T = lambda p: (int(round((p[0] + 6) * k * 16)), int(round((p[1] + 6) * k * 16)))
ink = np.zeros((S, S), np.float32)
w = int(round(stroke_px(size) * ss))
for pts, closed in chain(lines):
cv2.polylines(ink, [np.array([T(p) for p in pts], np.int32)], closed, 1.0, w, cv2.LINE_AA, 4)
a = cv2.resize(np.clip(ink, 0, 1), (size, size), interpolation=cv2.INTER_AREA)
out = np.empty((size, size, 4), np.uint8)
out[..., :3] = hex2bgr(color)
out[..., 3] = (a * 255).round()
return out
def capsules(lines, inset, k, width):
"""The mark's lines as path data: each line's outline - a capsule, round at both ends - its
0..100 box scaled by k and moved inset from the edges. Filled, never stroked: GTK and the
shell recolor a symbolic icon by setting its fill, and leave a stroke as it is. The capsules
all turn the same way, so where they overlap at the corners the nonzero fill joins them into
one round-cornered shape."""
r = width / 2
xy = lambda p: f"{p[0]:.2f} {p[1]:.2f}"
d = []
for a, b in lines:
a, b = inset + np.asarray(a) * k, inset + np.asarray(b) * k
u = (b - a) / np.linalg.norm(b - a)
n = np.array([-u[1], u[0]]) * r
arc = f"A{r:g} {r:g} 0 0 0"
d.append(f"M{xy(a + n)} L{xy(b + n)} {arc} {xy(b - n)} L{xy(a - n)} {arc} {xy(a + n)} Z")
return " ".join(d)
def svg(lines, size, inset, width, color):
"""The mark as a size px SVG, its 0..100 box inset from the edges, its lines width px wide."""
return (f'<svg xmlns="http://www.w3.org/2000/svg" width="{size}" height="{size}" viewBox="0 0 {size} {size}">\n'
f'<path d="{capsules(lines, inset, (size - 2 * inset) / 100, width)}" fill="{color}"/>\n</svg>\n')
# The installer's app icon, a tile in Tela's own geometry so it sits among Tela's app icons: 64 px
# on Tela's 16.933 grid, the rounded square in the folder color with Tela's white film over it at
# 10%, and the mark in the folder's glyph color, fitted to a box in the middle.
TILE, TILE_BOX = 16.933, 9.26
def tile(lines):
folder, glyph, white = PAL["icons"]["folder"], PAL["icons"]["folder_glyph"], PAL["neutral"]["a"]
rect = 'x="1.058" y="1.058" width="14.817" height="14.817" rx="1.587"'
inset = (TILE - TILE_BOX) / 2
return (f'<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 {TILE} {TILE}">\n'
f'<rect {rect} fill="{folder}"/>\n'
f'<rect {rect} fill="{white}" opacity=".1"/>\n'
f'<path d="{capsules(lines, inset, TILE_BOX / 100, 0.8)}" fill="{glyph}"/>\n</svg>\n')
# name: (size, inset, line width, color)
SVGS = {
# the color mark, the app icon at any size
"": (112, 6, 1.2, CYAN),
# GNOME's symbolic icon: on a 16 px grid, one color the toolkit replaces with the theme's
# (#2e3436 is the one it looks for), a line thick enough to read at 16 px
"-symbolic": (16, 6 * 16 / 112, 1.5, "#2e3436"),
# the Activities button of Orchis' GNOME Shell theme (its -i option): 48 px, white, as the
# theme's own icons are; the shell tints nothing, so the line is drawn at panel weight
"-activities": (48, 6 + 6 * 36 / 112, 3, "#fff"),
}
SIZES = [64, 48, 32, 24, 16] # above 64 px the SVG is the icon
for variant, spec in SVGS.items():
open(f"{OUT}/{NAME}{variant}.svg", "w").write(svg(LINES, *spec))
# The Construct app's tile is the mark. The installer's is the mark set back with an arrow down into
# its corner: both are on the live stick, and one tile for two apps read as the same app twice
# (the design review's round 1, all three reviewers).
INSTALL = [((a[0] * 0.72, a[1] * 0.72), (b[0] * 0.72, b[1] * 0.72)) for a, b in LINES] + [
((86, 52), (86, 96)), ((72, 82), (86, 96)), ((86, 96), (100, 82))]
open(f"{OUT}/io.github.construct_linux.Construct.svg", "w").write(tile(LINES))
open(f"{OUT}/io.github.construct_linux.Installer.svg", "w").write(tile(INSTALL))
for s in SIZES:
cv2.imwrite(f"{OUT}/{NAME}-{s}.png", render(LINES, s, CYAN))
print(f"{OUT}/: {NAME} -> svg, symbolic and activities svg, png {SIZES}; the installer's and the app's tile")