-
Notifications
You must be signed in to change notification settings - Fork 0
/
CenteredLogo.py
119 lines (107 loc) · 3.86 KB
/
CenteredLogo.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
import drawsvg as dw
import BaseLogo as base
class CenteredLogo(base.BaseLogo):
def __init__(
self,
canvas_dimensions: tuple[int, int],
background_color: str,
major_curve_color: str,
minor_curve_color: str,
curve_height: int,
curve_width: int,
curve_thickness: int,
separation: int,
major_curve_multiplier: int,
minor_curve_multiplier: int,
logo_scale: float,
filename: str,
debug: bool,
):
# Define output name and use of debug mode
self.filename = filename
self.debug = debug
# Set up image and color background
self.canvas_dimensions = canvas_dimensions
self.d = dw.Drawing(
self.canvas_dimensions[0],
self.canvas_dimensions[1],
)
self.background_color = background_color
self.draw_background(
self.canvas_dimensions[0],
self.canvas_dimensions[1],
self.background_color,
)
# Ingest curve related parameters
self.major_curve_color = major_curve_color
self.minor_curve_color = minor_curve_color
self.minor_curve_multiplier = minor_curve_multiplier
self.major_curve_multiplier = major_curve_multiplier
self.logo_scale = logo_scale
# Calculate shared curve parameters
self.curve_height = int(curve_height * self.logo_scale)
self.curve_width = int(curve_width * self.logo_scale)
self.thickness = int(curve_thickness * self.logo_scale)
# Calculate values relating to the two halves of the logo
self.copy_offset_major = int(-separation * self.logo_scale)
self.copy_offset_minor = self.copy_offset_major + (
(self.major_curve_multiplier + self.minor_curve_multiplier)
* self.curve_height
)
# Calculate centered logo origin
self.logo_origin = (
(self.canvas_dimensions[0] - self.curve_width) / 2,
(
self.canvas_dimensions[1]
- (self.major_curve_multiplier * self.curve_height)
- (self.copy_offset_major / 2)
)
/ 2,
)
# Calculate major curve parameters
self.major_curve_size = (
self.curve_width,
self.major_curve_multiplier * self.curve_height,
)
self.major_curve_end = (
self.logo_origin[0] + self.major_curve_size[0],
self.logo_origin[1] + self.major_curve_size[1],
)
self.major_curve_offset = (0 * self.logo_scale, -100 * logo_scale)
# Calculate minor curve parameters
self.minor_curve_size = (
self.curve_width,
-self.minor_curve_multiplier * self.curve_height,
)
self.minor_curve_end = (
self.logo_origin[0] + self.minor_curve_size[0],
self.logo_origin[1] + self.minor_curve_size[1],
)
self.minor_curve_offset = (
self.major_curve_offset[0],
-self.major_curve_offset[1],
)
# Draw
self.draw_major_curves(
drawing=self.d,
start=self.logo_origin,
end=self.major_curve_end,
thickness=self.thickness,
offset=self.major_curve_offset,
copy_offset=self.copy_offset_major,
color=self.major_curve_color,
debug=self.debug,
)
self.draw_minor_curves(
drawing=self.d,
start=self.logo_origin,
end=self.minor_curve_end,
thickness=self.thickness,
offset=self.minor_curve_offset,
copy_offset=self.copy_offset_minor,
color=self.minor_curve_color,
debug=self.debug,
)
# Save to file(s)
self.save_svg(filename=self.filename)
self.save_png(filename=self.filename)