读取pnm文件的Python程序

2024-06-16 08:29:17 发布

您现在位置:Python中文网/ 问答频道 /正文

pnm需要一个程序来创建一个文件华特堡教育大学图形.py找到库here。到目前为止,我得到的是:

from graphics import *

#Function chunks the list into groups of n, for example,
#List = ['2', '3', '4', '5', '6', '7', '8', '9', '10']
#with chucker lists becomes ['2', '3', '4'] and ['5','6','7'] and so on

def chunker(seq, size):
    return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))

def main():

fText =open("rainbowGS1.pnm", "r")
data = fText.readlines()
fText.close()

for ch in chunker(data[3:], 3):
    print ch

我不知道如何使用setPixel(x,y,color)函数找到here,以及color=color_RGB(255,0,0)函数来设置这些组和它们的RGB值。我不能使用color_rgb(ch),因为这个函数接受3个参数。通过使用color_rgb(ch),将传递一个参数。非常感谢您的帮助,谢谢!在


Tags: and函数inposfordatasizehere