Split out some functions for generating icons
This commit is contained in:
parent
a77405cf07
commit
0041a8a3c1
|
@ -15,21 +15,29 @@ BORDER_RADIUS = 10
|
|||
with open("workspace_icon_template.data") as f:
|
||||
TEMPLATE = f.read()
|
||||
|
||||
def define_globals(data, width, height):
|
||||
data = data.replace("{{WIDTH}}", str(width))
|
||||
data = data.replace("{{HEIGHT}}", str(height))
|
||||
data = data.replace("{{STROKE_COLOR}}", STROKE_COLOR)
|
||||
data = data.replace("{{STROKE_WIDTH}}", str(STROKE_WIDTH))
|
||||
return data
|
||||
|
||||
def draw_outer_rectangle(data, width, height):
|
||||
data = data.replace("{{BORDER_RADIUS}}", str(BORDER_RADIUS))
|
||||
data = data.replace("{{RECTANGLE_X}}", str(STROKE_WIDTH / 2))
|
||||
data = data.replace("{{RECTANGLE_Y}}", str(STROKE_WIDTH / 2))
|
||||
data = data.replace("{{RECTANGLE_WIDTH}}", str(width - STROKE_WIDTH))
|
||||
data = data.replace("{{RECTANGLE_HEIGHT}}", str(height - STROKE_WIDTH))
|
||||
return data
|
||||
|
||||
def generate_icons(n_rows, n_cols):
|
||||
for i in range(1, n_rows * n_cols + 1):
|
||||
filename = f"{ICON_NAME_PREFIX}_{n_rows}x{n_cols}_{i}.svg"
|
||||
width = n_cols * WORKSPACE_WIDTH
|
||||
height = n_rows * WORKSPACE_HEIGHT
|
||||
data = TEMPLATE
|
||||
data = data.replace("{{WIDTH}}", str(width))
|
||||
data = data.replace("{{HEIGHT}}", str(height))
|
||||
data = data.replace("{{STROKE_COLOR}}", STROKE_COLOR)
|
||||
data = data.replace("{{STROKE_WIDTH}}", str(STROKE_WIDTH))
|
||||
data = data.replace("{{BORDER_RADIUS}}", str(BORDER_RADIUS))
|
||||
data = data.replace("{{RECTANGLE_X}}", str(STROKE_WIDTH / 2))
|
||||
data = data.replace("{{RECTANGLE_Y}}", str(STROKE_WIDTH / 2))
|
||||
data = data.replace("{{RECTANGLE_WIDTH}}", str(width - STROKE_WIDTH))
|
||||
data = data.replace("{{RECTANGLE_HEIGHT}}", str(height - STROKE_WIDTH))
|
||||
data = define_globals(data, width, height)
|
||||
data = draw_outer_rectangle(data, width, height)
|
||||
data += "</svg>"
|
||||
with open(filename, "w") as f:
|
||||
f.write(data)
|
||||
|
|
Loading…
Reference in New Issue