This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logo-maker.py
executable file
·144 lines (123 loc) · 3.67 KB
/
logo-maker.py
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
#!/usr/bin/env python3
# generate xdosc_logo.svg
# Copyright © 2017 CKJ <ckj996@gmail.com>
# MIT License
#
# Usage: ./logo-maker > xdosc_logo.svg
#
from math import sqrt
#
# custom parameters
#
canvas = 512 # canvas size
radius = 240 # radius of main circle
s_radius_ratio = .850 # ratio to radius
s_corner_ratio = .224 # ratio to radius
s_width_ratio = .092 # ratio to radius
s_color = "#000000"
bg_color = "#FFFFFF"
petal_colors = (
"#F44336", # 1 o'clock
"#FF9800", # 3 o'clock
"#4CAF50", # 7 o'clock
"#FFEB3B", # 5 o'clock
"#2196F3", # 9 o'clock
"#9C27B0", # 11 o'clock
)
#
# parameters - DO NOT change
#
s_radius = radius * s_radius_ratio
s_corner = radius * s_corner_ratio
s_width = radius * s_width_ratio
p_width_ratio = (1 - s_radius_ratio) * sqrt(3) / 2 - s_width_ratio / 2
p_radius_ratio = 1 - p_width_ratio / sqrt(3)
p_width = radius * p_width_ratio
p_radius = radius * p_radius_ratio
base = (canvas / 2, canvas / 2)
base_vectors = (
(0, -2),
(sqrt(3), -1),
(sqrt(3), 1),
(0, 2),
(-sqrt(3), 1),
(-sqrt(3), -1),
)
s_rules = (
(1, (s_width * 0.75, s_width * 0.75 / sqrt(3))),
(0, (0, 0)),
(5, (0, 0)),
(5, (0, s_corner)),
(2, (0, -s_corner)),
(2, (0, 0)),
(3, (0, 0)),
(4, (-s_width * 0.75, -s_width * 0.75 / sqrt(3))),
)
#
# vector functions
#
def scale(vector, factor):
(x, y) = vector
return (x * factor, y * factor)
def add(vector1, vector2):
(x1, y1) = vector1
(x2, y2) = vector2
return (x1 + x2, y1 + y2)
def make_points(base, vector_set, factor):
return [add(base, scale(vector, factor)) for vector in vector_set]
def make_points_by_rules(points, rules):
return [add(points[i], vector) for (i, vector) in rules]
def make_points_attr(points):
str = 'points="'
(first_point, other_points) = (points[0], points[1:])
str += "%f %f" % first_point
for point in other_points:
str += ", %f %f" % point
str += '"'
return str
def qrint(str):
print(str, end = ' ')
def print_xml_header():
print('<?xml version="1.0" encoding="UTF-8" standalone="no"?>')
def print_svg_header(width, height):
qrint('<svg version="1.1" baseProfile="full"')
qrint('width="%d" height="%d"' % (width, height))
print('xmlns="http://www.w3.org/2000/svg">')
def print_svg_footer():
print('</svg>')
def print_polygon(points, fill, stroke, width):
qrint("<polygon")
qrint('fill="%s"' % fill)
qrint('stroke="%s"' % stroke)
qrint('stroke-width="%f"' % width)
qrint('stroke-linecap="butt"')
qrint('stroke-linejoin="miter"')
qrint(make_points_attr(points))
print("/>")
def print_polyline(points, fill, stroke, width):
qrint("<polyline")
qrint('fill="%s"' % fill)
qrint('stroke="%s"' % stroke)
qrint('stroke-width="%f"' % width)
qrint('stroke-linecap="butt"')
qrint('stroke-linejoin="miter"')
qrint(make_points_attr(points))
print("/>")
def print_petals(points):
for i in range(0, 6):
p, q, fill = points[i], points[(i + 1) % 6], petal_colors[i]
qrint("<path")
qrint('fill="%s"' % fill)
qrint('d="M %f %f L %f %f A %f %f 0 0 0 %f %f"' % (p + q + (radius, radius) + p))
print("/>")
outer_points = make_points(base, base_vectors, radius / 2)
padding_points = make_points(base, base_vectors, p_radius / 2)
inner_points = make_points(base, base_vectors, s_radius / 2)
s_points = make_points_by_rules(inner_points, s_rules)
print_xml_header()
print_svg_header(canvas, canvas)
print_polygon(outer_points, bg_color, "none", 0)
print_polyline(s_points, "none", s_color, s_width)
print_polygon(padding_points, "none", bg_color, p_width)
print_petals(outer_points)
print_svg_footer()