|
@@ -39,65 +39,56 @@ def rot_p(p_center, p, angle_d):
|
39
|
39
|
|
40
|
40
|
def read_image(filename, path_steps, volume_percent, angle_d):
|
41
|
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
|
57
|
for i in range(0, 2):
|
81
|
58
|
if p[i] < p_min[i]:
|
82
|
59
|
p_min[i] = p[i]
|
83
|
60
|
if p[i] > p_max[i]:
|
84
|
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
|
93
|
print("min={} max={}".format(p_min, p_max))
|
103
|
94
|
print("center={} ".format(p_center))
|
|
@@ -133,15 +124,24 @@ def read_image(filename, path_steps, volume_percent, angle_d):
|
133
|
124
|
for step in range(0, ps):
|
134
|
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
|
146
|
return data
|
147
|
147
|
|
|
@@ -156,7 +156,7 @@ def main():
|
156
|
156
|
parser = argparse.ArgumentParser(
|
157
|
157
|
prog=sys.argv[0],
|
158
|
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
|
161
|
parser.add_argument("input", help="Input SVG image file path.")
|
162
|
162
|
parser.add_argument("-o", "--output", dest="output", default="out.wav",
|