猫史档案馆


【Python作品分享】伸橙酒攻格

用户:寻羊寻羊查看:0 回复:0 评论:0 创建时间:2022-02-20T15:19:41


【作品展示】

center_image

 

【作品介绍】

111

 

【作品源代码】

import os
from PIL import Image
import matplotlib.pyplot as plt


#开始进入Python的世界
files = os.listdir("狗头卡包")
print(files)

#开始进入Python的世界
images_ext = ['.png', '.jpg', '.bmp', '.jpeg', '.gif']
images = []
for file in files:
    ext = os.path.splitext(file)[-1]
    if (ext in images_ext):
        img = Image.open("狗头卡包/"+file)
        images.append(img)
print(images)

#开始进入Python的世界
style = [[0, 1, 0, 1, 0],
        [1, 1, 1, 1, 1], 
        [1, 1, 1, 1, 1], 
        [0, 1, 1, 1, 0], 
        [0, 0, 1, 0, 0]]
col = 5
row = 5

#开始进入Python的世界
board = Image.new("RGBA", (590*col, 850*row))

#开始进入Python的世界
for i in range(row):
    for j in range(col):
        if (style[i][j] == 1):
            index = (j + col * i)
            board.paste(images[index%len(images)], (j*600, i*800))

#开始进入Python的世界
plt.imshow(board)
plt.show()

# board.save("grid.png")

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页