demo1

#coding=utf-8
from PIL import Image
img = Image.new("RGB",(5,5))###创建一个5*5的图片
pixTuple = (255,0,255,15)###三个参数依次为R,G,B,A   R:红 G:绿 B:蓝 A:透明度
for i in range(5):
    for j in range(5):
        img.putpixel((i,j),pixTuple)
img.save("bb.png")

 

demo2

import time
from PIL import Image
with open("aa-1.log","r") as f:
    costlist=eval(f.read())
img = Image.new("RGB",(792,675))###创建图片
single=[]
count=0
for i in range(600):
    for j in range(600):
        x=int(costlist[count])
        #if(x not in single):
            #single.append(x)
        if(x<10):
            pixTuple = (255,182,193,x)
            img.putpixel((i,j),pixTuple)
        elif(x<20):
            pixTuple = (255,20,147,x)
            img.putpixel((i,j),pixTuple)
        elif(x<30):
            pixTuple = (30,144,255,x)
            img.putpixel((i,j),pixTuple)
        elif(x<40):
            pixTuple = (135,206,235,x)
            img.putpixel((i,j),pixTuple)
        elif(x<50):
            pixTuple = (30,144,255,x)
            img.putpixel((i,j),pixTuple)
        elif(x<60):
            pixTuple = (127,255,170,x)
            img.putpixel((i,j),pixTuple)
        elif(x<70):
            pixTuple = (144,238,144,x)
            img.putpixel((i,j),pixTuple)
        elif(x<80):
            pixTuple = (255,255,0,x)
            img.putpixel((i,j),pixTuple)
        elif(x<90):
            pixTuple = (255,215,0,x)
            img.putpixel((i,j),pixTuple)
        elif(x<=100):
            pixTuple = (250,128,114,x)
            img.putpixel((i,j),pixTuple)
        count+=1
img.save("bb.png")
#print(single)