小编asm*_*ith的帖子

PPM图像到Python中的ASCII艺术

我必须创建一个程序,从命令行读取文件并将其转换为ASCII艺术.我使用的是PPM格式,这里是项目的链接.

这是我到目前为止:

import sys

def main(filename):
    image = open(filename)
    #reads through the first three lines
    color = image.readline().splitlines()
    size_width, size_height = image.readline().split()
    max_color = image.readline().splitlines()

    #reads the body of the file
    pixels = image.read().split()
    red = 0
    green = 0
    blue = 0
    r_g_b_value = []
    #pulls out the values of each tuple and coverts it to its grayscale value 
    for i in pixels:
        if i !=  "\n" or " ":
            if len(i) == 3:
                red = int(i[0]) …
Run Code Online (Sandbox Code Playgroud)

python ascii-art python-3.x

8
推荐指数
2
解决办法
9908
查看次数

标签 统计

ascii-art ×1

python ×1

python-3.x ×1