소스 검색

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

Thomas Buck 8 달 전
부모
커밋
890dd05d66
2개의 변경된 파일16개의 추가작업 그리고 12개의 파일을 삭제
  1. 2
    2
      Makefile
  2. 14
    10
      render.py

+ 2
- 2
Makefile 파일 보기

@@ -27,11 +27,11 @@ output:
27 27
 	mkdir output
28 28
 
29 29
 output/%.wav: %.svg
30
-	./render.py -s 192000 -o $@ $<
30
+	./render.py -s 192000 -i 5 -o $@ $<
31 31
 
32 32
 output/%_rotate.wav: %.svg
33 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 35
 	done
36 36
 	ffmpeg -f concat -safe 0 -i <( for f in output/$(@F)_*.wav; do echo "file '$$(pwd)/$$f'"; done ) $@
37 37
 	rm output/$(@F)_*.wav

+ 14
- 10
render.py 파일 보기

@@ -70,7 +70,7 @@ def read_image(filename, path_steps, volume_percent, angle_d):
70 70
         if dist_curr < dist_min:
71 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 75
     # find min max for all rotatations
76 76
     for segment in path:
@@ -127,16 +127,20 @@ def read_image(filename, path_steps, volume_percent, angle_d):
127 127
         p = interpolate(p1, p2, f)
128 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 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 144
     add_point(points[0])
141 145
 
142 146
     return data
@@ -163,8 +167,8 @@ def main():
163 167
                         help="Samplerate of output file in Hz. Defaults to 44.1kHz.")
164 168
     parser.add_argument("-v", "--volume", dest="volume", default=100.0, type=float,
165 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 172
     parser.add_argument("-r", "--rotate", dest="angle_d", default=0.0, type=float,
169 173
                         help="Angle to rotate image, in degrees. Defaults to 0 deg.")
170 174
 

Loading…
취소
저장