[英]Interpolate/Resize ascii art in python?
I want to resize some ascii art.我想调整一些 ascii 艺术的大小。 Say it looks like this:
说它看起来像这样:
..K
.T.
.A.
I want to upscale it, by some number n, so it will look like this (n=2)我想将它放大一些 n,所以它看起来像这样 (n=2)
....KK
....KK
..TT..
..TT..
..AA..
..AA..
One way I thought about doing this was to convert the text into a matrix of their ascii values and use some interpolation function to resize the matrix, and convert it back to text to achieve the desired result, but I have not been able to find a function that will do that for me.我想这样做的一种方法是将文本转换为其 ascii 值的矩阵,并使用一些插值函数来调整矩阵的大小,然后将其转换回文本以获得所需的结果,但我一直无法找到可以为我做到这一点的功能。
What is the easiest way to do this.什么是最简单的方法来做到这一点。 If it makes it simpler, you can assume that n is always 4. (Because in my current situation this is the scale I need)
如果它更简单,您可以假设 n 始终为 4。(因为在我目前的情况下,这是我需要的比例)
Assuming you have a file test.txt
with following content:假设您有一个包含以下内容的文件
test.txt
:
..K
.T.
.A.
The following code will read the file and prodcue an output file test_out.txt
which contains horizontally and vertically multiplied characters, depending what you specify for N
:以下代码将读取文件并生成输出文件
test_out.txt
,其中包含水平和垂直相乘的字符,具体取决于您为N
指定的内容:
N = 4
with open('test.txt', 'r') as f:
with open('test_out.txt', 'w') as out_f:
for line in f:
# Repeat characters N times horizontally
output = "".join([N * c for c in line.strip()])
# Repeat lines N times vertically
for _ in range(N):
out_f.write(output + '\n')
....KK
....KK
..TT..
..TT..
..AA..
..AA..
........KKKK
........KKKK
........KKKK
........KKKK
....TTTT....
....TTTT....
....TTTT....
....TTTT....
....AAAA....
....AAAA....
....AAAA....
....AAAA....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.