Browse Source

split toolbox logo svg into two paths. render them both, to try to remove connection line. does not work perfectly yet.

Thomas Buck 10 months ago
parent
commit
d3ee71767e
2 changed files with 74 additions and 66 deletions
  1. 60
    60
      render.py
  2. 14
    6
      toolbox.svg

+ 60
- 60
render.py View File

39
 
39
 
40
 def read_image(filename, path_steps, volume_percent, angle_d):
40
 def read_image(filename, path_steps, volume_percent, angle_d):
41
     paths, attributes = svg2paths(filename)
41
     paths, attributes = svg2paths(filename)
42
-    path = paths[0]
43
-    if len(paths) > 1:
44
-        print("WARNING: multiple paths in file. will just draw first one.")
45
-
46
-    print("paths={} segments={}".format(len(paths), len(path)))
47
-
48
-    points = [[path[0].start.real, path[0].start.imag]]
49
-    p_min = [points[0][0], points[0][1]]
50
-    p_max = [points[0][0], points[0][1]]
51
-
52
-    # find center
53
-    dist_min = float('inf')
54
-    dist_max = 0
55
-    p_prev = p_min
56
-    for segment in path:
57
-        p = [segment.end.real, segment.end.imag]
58
-        for i in range(0, 2):
59
-            if p[i] < p_min[i]:
60
-                p_min[i] = p[i]
61
-            if p[i] > p_max[i]:
62
-                p_max[i] = p[i]
63
-
64
-        dist_curr  = (p[0] - p_prev[0]) * (p[0] - p_prev[0])
65
-        dist_curr += (p[1] - p_prev[1]) * (p[1] - p_prev[1])
66
-        dist_curr  = math.sqrt(dist_curr)
67
-        p_prev = p
68
-        if dist_curr > dist_max:
69
-            dist_max = dist_curr
70
-        if dist_curr < dist_min:
71
-            dist_min = dist_curr
42
+    print("paths={}".format(len(paths)))
72
 
43
 
73
-    p_center = [ p_min[0] + (p_max[0] - p_min[0]) / 2, p_min[1] + (p_max[1] - p_min[1]) / 2 ]
44
+    p0 = [paths[0][0].start.real, paths[0][0].start.imag]
45
+    p_min = [p0[0], p0[1]]
46
+    p_max = [p0[0], p0[1]]
74
 
47
 
75
-    # find min max for all rotatations
76
-    for segment in path:
77
-        p_org = [segment.end.real, segment.end.imag]
78
-        for a in range(0, 360, 5):
79
-            p = rot_p(p_center, p_org , a)
48
+    for path in paths:
49
+        print("segments={}".format(len(path)))
50
+
51
+        # find center
52
+        dist_min = float('inf')
53
+        dist_max = 0
54
+        p_prev = p_min
55
+        for segment in path:
56
+            p = [segment.end.real, segment.end.imag]
80
             for i in range(0, 2):
57
             for i in range(0, 2):
81
                 if p[i] < p_min[i]:
58
                 if p[i] < p_min[i]:
82
                     p_min[i] = p[i]
59
                     p_min[i] = p[i]
83
                 if p[i] > p_max[i]:
60
                 if p[i] > p_max[i]:
84
                     p_max[i] = p[i]
61
                     p_max[i] = p[i]
85
 
62
 
86
-    p = [path[0].start.real, path[0].start.imag]
87
-    p = rot_p(p_center, p , angle_d)
88
-    points = [p]
89
-    # p_min = [points[0][0], points[0][1]]
90
-    # p_max = [points[0][0], points[0][1]]
91
-    for segment in path:
92
-        p = [segment.end.real, segment.end.imag]
93
-        p = rot_p(p_center, p , angle_d)
63
+            dist_curr = math.sqrt((p[0] - p_prev[0]) ** 2 + (p[1] - p_prev[1]) ** 2)
64
+            p_prev = p
65
+            if dist_curr > dist_max:
66
+                dist_max = dist_curr
67
+            if dist_curr < dist_min:
68
+                dist_min = dist_curr
94
 
69
 
95
-        for i in range(0, 2):
96
-            if p[i] < p_min[i]:
97
-                p_min[i] = p[i]
98
-            if p[i] > p_max[i]:
99
-                p_max[i] = p[i]
100
-        points.append(p)
70
+    p_center = [ p_min[0] + (p_max[0] - p_min[0]) / 2, p_min[1] + (p_max[1] - p_min[1]) / 2 ]
71
+
72
+        # find min max for all rotations
73
+        #for segment in path:
74
+        #    p_org = [segment.end.real, segment.end.imag]
75
+        #    for a in range(0, 360, 5):
76
+        #        p = rot_p(p_center, p_org , a)
77
+        #        for i in range(0, 2):
78
+        #            if p[i] < p_min[i]:
79
+        #                p_min[i] = p[i]
80
+        #            if p[i] > p_max[i]:
81
+        #                p_max[i] = p[i]
82
+
83
+    for path in paths:
84
+        for segment in path:
85
+            p = [segment.end.real, segment.end.imag]
86
+            p = rot_p(p_center, p, angle_d)
87
+            for i in range(0, 2):
88
+                if p[i] < p_min[i]:
89
+                    p_min[i] = p[i]
90
+                if p[i] > p_max[i]:
91
+                    p_max[i] = p[i]
101
 
92
 
102
     print("min={} max={}".format(p_min, p_max))
93
     print("min={} max={}".format(p_min, p_max))
103
     print("center={} ".format(p_center))
94
     print("center={} ".format(p_center))
133
         for step in range(0, ps):
124
         for step in range(0, ps):
134
             add_segment(p1, p2, step / ps)
125
             add_segment(p1, p2, step / ps)
135
 
126
 
136
-    # walk path forwards
137
-    for n in range(0, len(points) - 1):
138
-        add_path(points[n], points[n + 1])
139
-    add_point(points[len(points) - 1])
140
-
141
-    # walk path backwards
142
-    for n in range(len(points) - 2, -1, -1):
143
-        add_path(points[n + 1], points[n])
144
-    add_point(points[0])
127
+    for path in paths:
128
+        p = [path[0].start.real, path[0].start.imag]
129
+        p = rot_p(p_center, p , angle_d)
130
+        points = [p]
131
+        for segment in path:
132
+            p = [segment.end.real, segment.end.imag]
133
+            p = rot_p(p_center, p , angle_d)
134
+            points.append(p)
135
+
136
+        # walk path forwards
137
+        for n in range(0, len(points) - 1):
138
+            add_path(points[n], points[n + 1])
139
+        add_point(points[len(points) - 1])
140
+
141
+        # walk path backwards
142
+        for n in range(len(points) - 2, -1, -1):
143
+            add_path(points[n + 1], points[n])
144
+        add_point(points[0])
145
 
145
 
146
     return data
146
     return data
147
 
147
 
156
     parser = argparse.ArgumentParser(
156
     parser = argparse.ArgumentParser(
157
         prog=sys.argv[0],
157
         prog=sys.argv[0],
158
         description='Render SVG path to vector XY audio file',
158
         description='Render SVG path to vector XY audio file',
159
-        epilog='Made by Thomas Buck <thomas@xythobuz.de>. Licensed as GPLv3.')
159
+        epilog='Made by Thomas Buck (thomas@xythobuz.de) and Philipp Schönberger (mail@phschoen.de). Licensed as GPLv3.')
160
 
160
 
161
     parser.add_argument("input", help="Input SVG image file path.")
161
     parser.add_argument("input", help="Input SVG image file path.")
162
     parser.add_argument("-o", "--output", dest="output", default="out.wav",
162
     parser.add_argument("-o", "--output", dest="output", default="out.wav",

+ 14
- 6
toolbox.svg View File

23
      inkscape:pagecheckerboard="0"
23
      inkscape:pagecheckerboard="0"
24
      inkscape:deskcolor="#d1d1d1"
24
      inkscape:deskcolor="#d1d1d1"
25
      inkscape:document-units="mm"
25
      inkscape:document-units="mm"
26
-     inkscape:zoom="16"
27
-     inkscape:cx="27.6875"
28
-     inkscape:cy="45.875"
26
+     inkscape:zoom="8"
27
+     inkscape:cx="14.5"
28
+     inkscape:cy="40.375"
29
      inkscape:window-width="1920"
29
      inkscape:window-width="1920"
30
      inkscape:window-height="1020"
30
      inkscape:window-height="1020"
31
      inkscape:window-x="0"
31
      inkscape:window-x="0"
38
      inkscape:label="Layer 1"
38
      inkscape:label="Layer 1"
39
      inkscape:groupmode="layer"
39
      inkscape:groupmode="layer"
40
      id="layer1"
40
      id="layer1"
41
-     transform="translate(-45.755199,-45.487921)">
41
+     transform="translate(-45.755199,-45.487921)"
42
+     style="display:inline">
42
     <path
43
     <path
43
        inkscape:connector-curvature="0"
44
        inkscape:connector-curvature="0"
44
        id="path32"
45
        id="path32"
45
        style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.0352778;stroke-opacity:1"
46
        style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.0352778;stroke-opacity:1"
46
-       d="m 54.805794,66.484453 -9.032612,-5.199858 0.0025,-10.567302 9.035378,-5.20901 9.028924,5.208587 v 4.160979 l -1.862843,1.104657 1.862843,1.074702 c -9.33e-4,1.40583 -1.88e-4,2.812388 0,4.218482 l -9.033236,5.209579 m 0.910765,-2.706542 5.99e-4,-0.0022 6.246178,-3.577918 0.0047,-2.060667 -1.864043,-1.075267 -1.899073,1.095516 V 55.99825 l 3.763116,-2.170818 v -2.029848 l -7.160824,-4.130957 -7.164416,4.133003 v 8.395441 l 6.190862,3.564702 v -7.281566 l -1.492427,0.863212 -1.871098,-1.079429 5.594315,-3.236454 1.871909,1.079994 -2.233905,1.290426 0.01604,8.376379"
47
-       sodipodi:nodetypes="cccccccccccccccccccccccccccccc" />
47
+       d="m 54.805794,66.484453 -9.032612,-5.199858 0.0025,-10.567302 9.035378,-5.20901 9.028924,5.208587 v 4.160979 l -1.862843,1.104657 1.862843,1.074702 c -9.33e-4,1.40583 -1.88e-4,2.812388 0,4.218482 l -9.033236,5.209579"
48
+       sodipodi:nodetypes="cccccccccc" />
49
+    <path
50
+       inkscape:connector-curvature="0"
51
+       id="path1"
52
+       style="display:inline;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.0352778;stroke-opacity:1"
53
+       d="m 55.717513,63.778727 5.99e-4,-0.0022 6.246178,-3.577918 0.0047,-2.060667 -1.864043,-1.075267 -1.899073,1.095516 V 55.99825 L 61.96899,53.827432 V 51.797584 L 54.808166,47.666627 47.64375,51.79963 v 8.395441 l 6.190862,3.564702 v -7.281566 l -1.492427,0.863212 -1.871098,-1.079429 5.594315,-3.236454 1.871909,1.079994 -2.233905,1.290426 0.01604,8.376379"
54
+       sodipodi:nodetypes="cccccccccccccccccccc"
55
+       transform="translate(-1.1666667e-6)" />
48
   </g>
56
   </g>
49
 </svg>
57
 </svg>

Loading…
Cancel
Save