绘制九宫格

 1 from PIL import Image,ImageDraw
 2 width,height = 300,300
 3 img =  Image.new('RGB',(width,height),(255,255,255))
 4 draw_obj =  ImageDraw.Draw(img)
 5 
 6 def get_color(x,y):
 7     a = x//100 + y//100
 8     if a == 0:
 9         return(255,0,0)
10     elif a == 1:
11         return(255,255,0)
12     elif a ==2:
13         return(255,0,255)
14     elif a == 3:
15         return(0,0,255)
16     elif a == 4:
17         return(0,255,255)
18     else:
19         return(0,0,0)
20 
21 for x in range(width):
22     for y in range(height):
23         draw_obj.point((x,y),fill=get_color(x,y))
24 img.show()

 

posted @ 2020-05-20 10:13  小他_W  阅读(384)  评论(0编辑  收藏  举报