找回密码
 中文实名注册
查看: 68|回复: 0

樊泽宇 奇怪的图片

[复制链接]

19

主题

92

帖子

874

积分

高级会员

Rank: 4

积分
874
发表于 2025-1-11 11:54:29 | 显示全部楼层 |阅读模式
[Python] 纯文本查看 复制代码
from PIL import Image
import random

def create_mining_map(width=100, height=200):
    # 定义颜色
    colors = {
        '地面': (139, 69, 19),  # 棕色(地面)
        '煤矿': (0, 0, 0),      # 黑色(煤矿)
        '铁矿': (192, 192, 192), # 银色(铁矿)
        '金矿': (255, 215, 0),   # 金色(金矿)
        '钻石': (0, 255, 255),   # 青色(钻石)
        '石头': (169, 169, 169), # 灰色(石头)
        '障碍': (128, 128, 128)  # 深灰色(障碍)
    }

    # 创建一个新的 RGB 图像
    img = Image.new('RGB', (width, height), 'white')
    pixels = img.load()  # 访问像素值

    # 填充图像
    for y in range(height):
        for x in range(width):
            if y == 0:  # 地面
                pixels[x, y] = colors['地面']
            elif y % 20 == 1:  # 每20个像素有一个煤矿
                pixels[x, y] = colors['煤矿']
            elif y % 20 == 2:  # 每20个像素有一个铁矿
                pixels[x, y] = colors['铁矿']
            elif y % 20 == 3:  # 每20个像素有一个金矿
                pixels[x, y] = colors['金矿']
            elif y % 20 == 4:  # 每20个像素有一个钻石
                pixels[x, y] = colors['钻石']
            elif y % 20 == 5:  # 每20个像素有一个石头
                pixels[x, y] = colors['石头']
            elif y % 20 == 6:  # 每20个像素有一个障碍
                pixels[x, y] = colors['障碍']
            else:  # 默认填充
                pixels[x, y] = colors['石头']  # 主要是石头

    # 生成随机生成的资源
    for y in range(1, height):
        if random.random() < 0.05:  # 5% 的概率放置随机资源
            x = random.randint(0, width - 1)
            resource = random.choice(['煤矿', '铁矿', '金矿', '钻石'])
            pixels[x, y] = colors[resource]

    # 保存图像
    img.save("mining_map.png")

if __name__ == "__main__":
    create_mining_map()
    print("挖矿地图已生成:mining_map.png")

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2025-3-15 00:22 , Processed in 0.038185 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表