|
@ -3,8 +3,11 @@ |
|
|
|
|
|
|
|
|
import yaml |
|
|
import yaml |
|
|
|
|
|
|
|
|
CASE_WIDTH = 48 |
|
|
BLOCK_LENGTH = 12 |
|
|
CASE_HEIGHT = 72 |
|
|
BLOCK_DISTANCE = 4 |
|
|
|
|
|
|
|
|
|
|
|
CASE_WIDTH = BLOCK_LENGTH * 4 + BLOCK_DISTANCE * 5 |
|
|
|
|
|
CASE_HEIGHT = BLOCK_LENGTH * 5 + BLOCK_DISTANCE * 6 |
|
|
|
|
|
|
|
|
CASE_DISTANCE_X = 80 |
|
|
CASE_DISTANCE_X = 80 |
|
|
CASE_DISTANCE_Y = 40 |
|
|
CASE_DISTANCE_Y = 40 |
|
@ -14,30 +17,6 @@ MAIN_MARGIN_Y = 8 |
|
|
|
|
|
|
|
|
LINK_OFFSET = 1 |
|
|
LINK_OFFSET = 1 |
|
|
|
|
|
|
|
|
# layer = [ |
|
|
|
|
|
# ["603EDF5CAFFF5E2"], # layer 0 |
|
|
|
|
|
# ["61BEC75CAFFF5E2","0C3EDF5CAFFF5E2"], # layer 1 |
|
|
|
|
|
# ["0DBEC75CAFFF5E2","EC34DF1CAFFF5E2"], # layer 2 |
|
|
|
|
|
# ["EDB4C71CAFFF5E2","EC34DFE42FFF5E2"], # layer 3 |
|
|
|
|
|
# ["EDB4C7E42FFF5E2"], # layer 4 |
|
|
|
|
|
# ["EDB4F8E50FFF5E2"], # layer 5 |
|
|
|
|
|
# ] |
|
|
|
|
|
# |
|
|
|
|
|
# link = [[ |
|
|
|
|
|
# [0, 1] # (0, 0) -> 1 |
|
|
|
|
|
# ], [ |
|
|
|
|
|
# [0], # (1, 0) -> 2 |
|
|
|
|
|
# [0, 1] # (1, 1) -> 2 |
|
|
|
|
|
# ], [ |
|
|
|
|
|
# [0], # (2, 0) -> 3 |
|
|
|
|
|
# [0, 1], # (2, 1) -> 3 |
|
|
|
|
|
# ], [ |
|
|
|
|
|
# [0], # (3, 0) -> 4 |
|
|
|
|
|
# [0], # (3, 1) -> 4 |
|
|
|
|
|
# ], [ |
|
|
|
|
|
# [0], # (4, 0) -> 5 |
|
|
|
|
|
# ]] |
|
|
|
|
|
|
|
|
|
|
|
raw_data = yaml.load(open('demo.yml').read(), Loader = yaml.FullLoader) |
|
|
raw_data = yaml.load(open('demo.yml').read(), Loader = yaml.FullLoader) |
|
|
layer = raw_data['layer'] |
|
|
layer = raw_data['layer'] |
|
|
link = raw_data['next'] |
|
|
link = raw_data['next'] |
|
@ -54,6 +33,7 @@ MAX_CASE_Y = len(layer) |
|
|
|
|
|
|
|
|
MAX_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X |
|
|
MAX_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def case_address(layer_num: int, layer_index: int) -> (int, int): |
|
|
def case_address(layer_num: int, layer_index: int) -> (int, int): |
|
|
|
|
|
|
|
|
case_number_x = len(layer[layer_num]) |
|
|
case_number_x = len(layer[layer_num]) |
|
@ -81,9 +61,9 @@ def link_address(start_layer_num: int, start_layer_index: int, end_layer_num: in |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def svg_rect(left: int, top: int, width: int, height: int): |
|
|
def svg_rect(left: int, top: int, width: int, height: int, line_width: int): |
|
|
return '<rect x="%d" y="%d" width="%d" height="%d" style="fill:pink;stroke-width:2;stroke:rgb(0,0,0)"/>' % ( |
|
|
return '<rect x="%d" y="%d" width="%d" height="%d" style="fill:pink;stroke-width:%d;stroke:rgb(0,0,0)"/>' % ( |
|
|
left, top, width, height |
|
|
left, top, width, height, line_width |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,6 +72,19 @@ def svg_line(start_x: int, start_y: int, end_x: int, end_y: int): |
|
|
start_x, start_y, end_x, end_y |
|
|
start_x, start_y, end_x, end_y |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def case_output(info: list, x_offset: int, y_offset: int): |
|
|
|
|
|
print(' ', svg_rect(x_offset, y_offset, CASE_WIDTH, CASE_HEIGHT, 2)) |
|
|
|
|
|
for (x, y, h, w) in info: |
|
|
|
|
|
|
|
|
|
|
|
left = BLOCK_LENGTH * x + BLOCK_DISTANCE * (x + 1) + x_offset |
|
|
|
|
|
top = BLOCK_LENGTH * y + BLOCK_DISTANCE * (y + 1) + y_offset |
|
|
|
|
|
width = BLOCK_LENGTH * w + BLOCK_DISTANCE * (w - 1) |
|
|
|
|
|
height = BLOCK_LENGTH * h + BLOCK_DISTANCE * (h - 1) |
|
|
|
|
|
|
|
|
|
|
|
print(' ', svg_rect(left, top, width, height, 1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MAIN_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X + MAIN_MARGIN_X * 2 |
|
|
MAIN_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X + MAIN_MARGIN_X * 2 |
|
|
MAIN_HEIGHT = MAX_CASE_Y * CASE_HEIGHT + (MAX_CASE_Y - 1) * CASE_DISTANCE_Y + MAIN_MARGIN_Y * 2 |
|
|
MAIN_HEIGHT = MAX_CASE_Y * CASE_HEIGHT + (MAX_CASE_Y - 1) * CASE_DISTANCE_Y + MAIN_MARGIN_Y * 2 |
|
|
|
|
|
|
|
@ -100,17 +93,13 @@ print('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height=" |
|
|
for layer_num in range(0, len(layer)): |
|
|
for layer_num in range(0, len(layer)): |
|
|
for layer_index in range(0, len(layer[layer_num])): |
|
|
for layer_index in range(0, len(layer[layer_num])): |
|
|
x, y = case_address(layer_num, layer_index) |
|
|
x, y = case_address(layer_num, layer_index) |
|
|
print(' ', svg_rect(x, y, CASE_WIDTH, CASE_HEIGHT)) |
|
|
case_output(layer[layer_num][layer_index], x, y) |
|
|
|
|
|
|
|
|
for layer_num in range(0, len(link)): |
|
|
for layer_num in range(0, len(link)): |
|
|
for layer_index in range(0, len(link[layer_num])): |
|
|
for layer_index in range(0, len(link[layer_num])): |
|
|
for next_index in range(0, len(link[layer_num][layer_index])): |
|
|
for next_index in range(0, len(link[layer_num][layer_index])): |
|
|
|
|
|
|
|
|
# print('(%d, %d) -> (%d, %d)' % (layer_num, layer_index, layer_num + 1, next_index)) |
|
|
|
|
|
x1, y1, x2, y2 = link_address(layer_num, layer_index, layer_num + 1, next_index) |
|
|
x1, y1, x2, y2 = link_address(layer_num, layer_index, layer_num + 1, next_index) |
|
|
print(' ', svg_line(x1, y1, x2, y2)) |
|
|
print(' ', svg_line(x1, y1, x2, y2)) |
|
|
|
|
|
|
|
|
# x1, y1, x2, y2 = link_address(0, 0, 1, 0) |
|
|
|
|
|
# print(' ', svg_line(x1, y1, x2, y2)) |
|
|
|
|
|
|
|
|
|
|
|
print('</svg>') |
|
|
print('</svg>') |
|
|