-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeflow.py
More file actions
34 lines (29 loc) · 1.06 KB
/
makeflow.py
File metadata and controls
34 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
from PIL import Image
from .common import TextureReader
import sys
import os
# timescale to repeat the source animation multiple times in the dst animation
def do_convert(srcf, dstf, timescale=1):
src = TextureReader(srcf)
w = src.size
nframe = 16
px = 1 # pixels down per 16'th of the animation
dsta = np.ndarray((nframe, w*2, w*2, src.nchan), np.uint8)
for iframe in range(nframe):
fr = src.get_frame(iframe / nframe * src.nframe * timescale)
fr = np.roll(fr, w//2, (0, 1)) # center the original texture
fr = np.roll(fr, iframe*px*w//nframe, 0) # directional flowing
fr = np.tile(fr, (2, 2, 1))
dsta[iframe] = fr
if src.mode == 'L':
dsta = dsta.reshape((w*nframe*2, w*2))
else:
dsta = dsta.reshape((w*nframe*2, w*2, src.nchan))
dstp = Image.fromarray(dsta, src.mode)
dstp.save(dstf)
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage:", os.path.basename(sys.argv[0]), "src.png dst.png")
sys.exit(1)
do_convert(*sys.argv[1:])