可以用python打印这个图案吗?

问题描述 投票:0回答:1

可以用python打印这个图案吗?

[s0][s1][s01]

[s01][s2][s012]

[s012][s3]x[s0123]

[s0123][s4]x[s01234]

这是针对 ffmpeg filter_complex 的。 因此,基本上它会搜索目录中的图像数量并构建以下命令供我用于不同的目的。 到目前为止,我已成功获得以下输出:

ffmpeg -loop 1 -t 5 -i 3.png -loop 1 -t 5 -i 5.png -loop 1 -t 5 -i 4.png -loop 1 -t 5 -i 6.png -loop 1 -t 5 -i 1.png -loop 1 -t 5 -i 2.png -filter_complex "[0]scale=816:1456[s0];[1]scale=816:1456[s1];[2]scale=816:1456[s2];[3]scale=816:1456[s3];[4]scale=816:1456[s4];[5]scale=816:1456[s5];

但我坚持获得上述模式。

PS:

在我的项目中,该模式将用于创建如下所示的内容:

"[s0][s1]xfade=transition=pixelize:duration=0.2:offset=4[s01];[s01][s2]xfade=transition=pixelize:duration=0.2:offset=8[s012];[s012][s3]xfade=transition=pixelize:duration=0.2:offset=12[s0123];[s0123][s4]xfade=transition=pixelize:duration=0.2:offset=16[s01234];[s01234][s5]xfade=transition=pixelize:duration=0.2:offset=20,format=yuv420p" out.mp4

我尝试在 for 循环中使用数组,但它没有提供预期的输出。

def print_pattern(num_lines):
    for i in range(num_lines):
        for j in range(i + 1):
            print(j, end='')
        print(' and', i + 1, 'and', end=' ')
        for j in range(i + 1):
            print(j, end='')
        for k in range(i + 1):
            print(k + j + 1, end='')
        print()

num_lines = 4  # Change this variable to control the number of lines
print_pattern(num_lines)

这是输出。

0 and 1 and 01
01 and 2 and 0123
012 and 3 and 012345
0123 and 4 and 01234567
python ffmpeg
1个回答
0
投票

给你:

def print_pattern(num_lines):
    for i in range(num_lines):
        fwd = "".join(map(str, range(i + 1)))
        rev = "".join(reversed(fwd))
        print(fwd, "and", i + 1, "and", rev)
        print()

输出:

0 and 1 and 0

01 and 2 and 10

012 and 3 and 210

0123 and 4 and 3210
© www.soinside.com 2019 - 2024. All rights reserved.