Browse Source

scale interpolated line step count according to line length, so all lines appear with the same brightness.

Thomas Buck 10 months ago
parent
commit
890dd05d66
2 changed files with 16 additions and 12 deletions
  1. 2
    2
      Makefile
  2. 14
    10
      render.py

+ 2
- 2
Makefile View File

27
 	mkdir output
27
 	mkdir output
28
 
28
 
29
 output/%.wav: %.svg
29
 output/%.wav: %.svg
30
-	./render.py -s 192000 -o $@ $<
30
+	./render.py -s 192000 -i 5 -o $@ $<
31
 
31
 
32
 output/%_rotate.wav: %.svg
32
 output/%_rotate.wav: %.svg
33
 	for number in {000..360..5} ; do \
33
 	for number in {000..360..5} ; do \
34
-	   ./render.py -s 192000 -t 0.1 -o output/$(@F)_$$number.wav -r $$number $< ; \
34
+	   ./render.py -s 192000 -i 5 -t 0.1 -o output/$(@F)_$$number.wav -r $$number $< ; \
35
 	done
35
 	done
36
 	ffmpeg -f concat -safe 0 -i <( for f in output/$(@F)_*.wav; do echo "file '$$(pwd)/$$f'"; done ) $@
36
 	ffmpeg -f concat -safe 0 -i <( for f in output/$(@F)_*.wav; do echo "file '$$(pwd)/$$f'"; done ) $@
37
 	rm output/$(@F)_*.wav
37
 	rm output/$(@F)_*.wav

+ 14
- 10
render.py View File

70
         if dist_curr < dist_min:
70
         if dist_curr < dist_min:
71
             dist_min = dist_curr
71
             dist_min = dist_curr
72
 
72
 
73
-    p_center = [ p_min[0] + (p_max[0] - p_min[0] )/2  ,  p_min[1] + (p_max[1] - p_min[1] )/2]
73
+    p_center = [ p_min[0] + (p_max[0] - p_min[0]) / 2, p_min[1] + (p_max[1] - p_min[1]) / 2 ]
74
 
74
 
75
     # find min max for all rotatations
75
     # find min max for all rotatations
76
     for segment in path:
76
     for segment in path:
127
         p = interpolate(p1, p2, f)
127
         p = interpolate(p1, p2, f)
128
         add_point(p)
128
         add_point(p)
129
 
129
 
130
-    for n in range(0, len(points) - 1):
131
-        for step in range(0, path_steps):
132
-            add_segment(points[n], points[n + 1], step / path_steps)
130
+    def add_path(p1, p2):
131
+        l = math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
132
+        ps = max(1, int(path_steps * l))
133
+        for step in range(0, ps):
134
+            add_segment(p1, p2, step / ps)
133
 
135
 
134
-    #add_point(points[len(points) - 1])
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])
135
 
140
 
141
+    # walk path backwards
136
     for n in range(len(points) - 2, -1, -1):
142
     for n in range(len(points) - 2, -1, -1):
137
-        for step in range(0, path_steps):
138
-            add_segment(points[n + 1], points[n], step / path_steps)
139
-
143
+        add_path(points[n + 1], points[n])
140
     add_point(points[0])
144
     add_point(points[0])
141
 
145
 
142
     return data
146
     return data
163
                         help="Samplerate of output file in Hz. Defaults to 44.1kHz.")
167
                         help="Samplerate of output file in Hz. Defaults to 44.1kHz.")
164
     parser.add_argument("-v", "--volume", dest="volume", default=100.0, type=float,
168
     parser.add_argument("-v", "--volume", dest="volume", default=100.0, type=float,
165
                         help="Volume of output file in percent. Defaults to 100%%.")
169
                         help="Volume of output file in percent. Defaults to 100%%.")
166
-    parser.add_argument("-i", "--interpolate", dest="interpolate", default=10, type=int,
167
-                        help="Steps on interpolated paths. Defaults to 10.")
170
+    parser.add_argument("-i", "--interpolate", dest="interpolate", default=3, type=int,
171
+                        help="Steps on interpolated paths. Defaults to 3.")
168
     parser.add_argument("-r", "--rotate", dest="angle_d", default=0.0, type=float,
172
     parser.add_argument("-r", "--rotate", dest="angle_d", default=0.0, type=float,
169
                         help="Angle to rotate image, in degrees. Defaults to 0 deg.")
173
                         help="Angle to rotate image, in degrees. Defaults to 0 deg.")
170
 
174
 

Loading…
Cancel
Save