-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_svg.py
More file actions
224 lines (195 loc) · 10.3 KB
/
generate_svg.py
File metadata and controls
224 lines (195 loc) · 10.3 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python3
"""
Generate SVG files for CodesWhat? org profile README.
Creates dark_mode.svg and light_mode.svg.
"""
import re
from pathlib import Path
def escape_xml(s):
"""Escape XML special characters."""
return s.replace('&', '&').replace('<', '<').replace('>', '>')
def generate_svg(mode="dark"):
"""Generate SVG content for the given color mode."""
if mode == "dark":
colors = {
'bg': '#0d1117',
'art_solid': '#c8ff00', # lime hyper green for #
'art_mid': '#5a7a00', # muted green for + -
'art_dim': '#1a2600', # dark green for .
'title': '#c8ff00', # lime green
'tagline': '#8b949e', # muted gray
'tagline2': '#6e7681', # dimmer gray
}
else:
colors = {
'bg': '#ffffff',
'art_solid': '#3300ff', # deep electric blue for #
'art_mid': '#8877cc', # muted blue for + -
'art_dim': '#e0dff0', # faint blue-gray for .
'title': '#3300ff', # deep electric blue
'tagline': '#555555', # medium gray
'tagline2': '#888888', # lighter gray
}
c = colors
width = 680
font_size = 11
art_line_height = 13
text_line_height = 24
y_start = 16
logo_art = [
" ########################## ",
" ################################## ",
" ########################################## ",
" ############++-..................-++############ ",
" ###########+-............................-+########### ",
" #########+-....................................-+######### ",
" #########-..........................................-######### ",
" ########+................................................+######## ",
" #######+-...................................................+####### ",
" ########-.....................................--++--...........-######## ",
" #######-...................................-###########+..........-####### ",
" #######-.........-+###########-............+##############+.........-####### ",
" #######.........-################+.........#######++++######+..........+###### ",
" #######.........-#######++++######+-.......-#####-.....-######-..........####### ",
" ######+.........-######-.......+#-..........------......-######-...........####### ",
" ######-.........######.................................-######-............-####### ",
" ######-.........-#####+...............................-#######-..............-###### ",
" ######..........-#####+.............................-#######-.................+######",
"######-..........-######.............................######-...................-######",
"######............######+.........-..................#####+.....................######",
"#####+.............#######+-..--+###+-..........................................+#####",
"#####+..............+#################-..............#####-.....................-#####",
"#####-...............-+#############-................#####+.....................-#####",
"#####-...................-+#####+-...................#####-.....................-#####",
"#####-..........................................................................-#####",
"#####+..........................................................................+#####",
"######..............-+++++-............-+++++-............-++++++...............+#####",
"######-.............-######-...........#######-...........######-...............######",
"######+..............-######..........#########..........+#####+...............-######",
" ######-..............+#####+........+#########+........-######................###### ",
" ######+...............######-......-###########-......-######................-###### ",
" ######-..............-######......######-######......+#####-...............-###### ",
" #######...............-#####+....+#####-..######....-#####+................####### ",
" #######-..............+#####-..-#####+...+#####+..-######-...............####### ",
" #######-.............-######-.######.....+#####-.######-..............-####### ",
" #######-.............-#####+######......-######+#####+..............-####### ",
" #######+.............###########-.......-###########..............+####### ",
" #######-............#########+.........+#########.............-######## ",
" ########-..........-#######+...........+#######-...........-######## ",
" #########-..............................-----...........-######### ",
" #########+..........................................+######### ",
" ##########-....................................-########## ",
" ###########+--...........................-+########### ",
" #############++-................--+############# ",
" ########################################## ",
" ################################## ",
" ######################### ",
]
# Build SVG with per-character coloring for depth
lines = []
for art in logo_art:
lines.append(("art", art))
lines.append(("blank", ""))
lines.append(("blank", ""))
lines.append(("title", "CodesWhat?"))
lines.append(("blank", ""))
lines.append(("tagline", "if you'd like to build better worlds together"))
lines.append(("tagline2", "...we mean software... reach out"))
# Calculate height
total_height = y_start
for typ, _ in lines:
if typ == "art":
total_height += art_line_height
elif typ == "blank":
total_height += text_line_height // 2
else:
total_height += text_line_height
height = total_height + 24
svg = f'''<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}">
<style>
@font-face {{
src: local('Consolas'), local('Monaco'), local('Menlo');
font-family: 'MonoFallback';
font-display: swap;
}}
text {{
font-family: 'MonoFallback', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
white-space: pre;
dominant-baseline: text-before-edge;
}}
</style>
<rect width="{width}" height="{height}" fill="{c['bg']}" rx="10"/>
'''
char_width = font_size * 0.6
y = y_start
for typ, content in lines:
if typ == "art" and content.strip():
# Render art with per-character color spans
# Group consecutive chars by color category
line_width = len(content) * char_width
start_x = (width - line_width) / 2
# Build runs of same-colored characters
runs = []
i = 0
while i < len(content):
ch = content[i]
if ch == '#':
color = c['art_solid']
elif ch in '+-':
color = c['art_mid']
elif ch == '.':
color = c['art_dim']
else:
i += 1
continue
# Collect run of same color
start = i
while i < len(content):
nch = content[i]
if nch == '#':
nc = c['art_solid']
elif nch in '+-':
nc = c['art_mid']
elif nch == '.':
nc = c['art_dim']
else:
break
if nc != color:
break
i += 1
x = start_x + start * char_width
text = escape_xml(content[start:i])
runs.append(f'<text x="{x:.1f}" y="{y}" fill="{color}" font-size="{font_size}px">{text}</text>')
svg += '\n'.join(runs) + '\n'
y += art_line_height
elif typ == "art":
y += art_line_height
elif typ == "title":
svg += f'<text x="{width // 2}" y="{y}" text-anchor="middle" fill="{c["title"]}" font-size="22px" font-weight="600" font-family="-apple-system, BlinkMacSystemFont, \'Segoe UI\', Helvetica, Arial, sans-serif">{escape_xml(content)}</text>\n'
y += text_line_height
elif typ == "tagline":
svg += f'<text x="{width // 2}" y="{y}" text-anchor="middle" fill="{c["tagline"]}" font-size="13px" font-family="-apple-system, BlinkMacSystemFont, \'Segoe UI\', Helvetica, Arial, sans-serif">{escape_xml(content)}</text>\n'
y += text_line_height
elif typ == "tagline2":
svg += f'<text x="{width // 2}" y="{y}" text-anchor="middle" fill="{c["tagline2"]}" font-size="12px" font-family="-apple-system, BlinkMacSystemFont, \'Segoe UI\', Helvetica, Arial, sans-serif">{escape_xml(content)}</text>\n'
y += text_line_height
elif typ == "blank":
y += text_line_height // 2
svg += '</svg>'
return svg
def main():
"""Generate both dark and light mode SVGs."""
script_dir = Path(__file__).parent
dark_svg = generate_svg("dark")
dark_path = script_dir / "profile" / "dark_mode.svg"
with open(dark_path, 'w', encoding='utf-8') as f:
f.write(dark_svg)
print(f"Generated: {dark_path}")
light_svg = generate_svg("light")
light_path = script_dir / "profile" / "light_mode.svg"
with open(light_path, 'w', encoding='utf-8') as f:
f.write(light_svg)
print(f"Generated: {light_path}")
if __name__ == "__main__":
main()