Browse Source

feat: add links between cases

legacy
Dnomd343 2 years ago
parent
commit
bf68fd5809
  1. 47
      svg-demo/svg_dump.py

47
svg-demo/svg_dump.py

@ -1,15 +1,17 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
CASE_WIDTH = 24 CASE_WIDTH = 48
CASE_HEIGHT = 36 CASE_HEIGHT = 72
CASE_DISTANCE_X = 40 CASE_DISTANCE_X = 80
CASE_DISTANCE_Y = 20 CASE_DISTANCE_Y = 40
MAIN_MARGIN_X = 10 MAIN_MARGIN_X = 10
MAIN_MARGIN_Y = 8 MAIN_MARGIN_Y = 8
LINK_OFFSET = 1
layer = [ layer = [
["603EDF5CAFFF5E2"], # layer 0 ["603EDF5CAFFF5E2"], # layer 0
["61BEC75CAFFF5E2","0C3EDF5CAFFF5E2"], # layer 1 ["61BEC75CAFFF5E2","0C3EDF5CAFFF5E2"], # layer 1
@ -61,24 +63,49 @@ def case_address(layer_num: int, layer_index: int) -> (int, int):
) )
def link_address(start_layer_num: int, start_layer_index: int, end_layer_num: int, end_layer_index: int) -> (int, int, int, int):
x1, y1 = case_address(start_layer_num, start_layer_index)
x2, y2 = case_address(end_layer_num, end_layer_index)
return (
x1 + int(CASE_WIDTH / 2),
y1 + CASE_HEIGHT + LINK_OFFSET,
x2 + int(CASE_WIDTH / 2),
y2 - LINK_OFFSET,
)
def svg_rect(left: int, top: int, width: int, height: int): def svg_rect(left: int, top: int, width: int, height: 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:2;stroke:rgb(0,0,0)"/>' % (
left, top, width, height left, top, width, height
) )
print('<svg xmlns="http://www.w3.org/2000/svg" version="1.1">') def svg_line(start_x: int, start_y: int, end_x: int, end_y: int):
return '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:black;stroke-width:1"/>' % (
start_x, start_y, end_x, end_y
)
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
print('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">' % (MAIN_WIDTH, MAIN_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)) print(' ', svg_rect(x, y, CASE_WIDTH, CASE_HEIGHT))
for layer_num in range(0, len(link)):
for layer_index in range(0, len(link[layer_num])):
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)
print(' ', svg_line(x1, y1, x2, y2))
# for case in [(0, 0), (1, 0), (1, 1)]: # (layer_num, layer_index) # x1, y1, x2, y2 = link_address(0, 0, 1, 0)
# x, y = case_address(case[0], case[1]) # print(' ', svg_line(x1, y1, x2, y2))
#
# print(' ', svg_rect(x, y, CASE_WIDTH, CASE_HEIGHT))
# print(case_address(case[0], case[1]))
print('</svg>') print('</svg>')

Loading…
Cancel
Save