背景需求:
【教学类-64-02】20240610色块眼力挑战(二)-2-25宫格&色差10-100(10倍)(星火讯飞)-CSDN博客文章浏览阅读360次,点赞17次,收藏13次。【教学类-64-02】20240610色块眼力挑战(二)-2-25宫格&色差10-100(10倍)(星火讯飞)https://blog.csdn.net/reasonsummer/article/details/139572789
通过观察,我觉得宫格数量不需要太大,色块太多,容易眼晕。(25宫格)
此外10-20的色差不容易分辨,30-100的色差对比都比较清楚,所以我只需要10-50的色差就可以了。
色差10
色差50
代码展示
1、色差范围从10-50
2、宫格数量从2-6
3、数量5张
'''
目的:不同的找不同色块小游戏(从2宫格-25宫格,色差从10,20^100)有提卡和答案,从难度1-10(难度1就是色差100,难度10是色彩10)
每种做5张,只要2-10宫格,色差从10-50(不容易看清)图片导入PPT
原作者:moyuweiqing
https://blog.csdn.net/moyuweiqing/article/details/134263628
改编:星火讯飞,阿夏
时间:2024年6月10日
'''
print('------1、图片和答案----------')
from PIL import Image, ImageDraw # 导入PIL库中的Image和ImageDraw模块
import numpy as np # 导入numpy库并简写为np
import random ,os # 导入random库
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\辨认色彩图'
new_path=path+r'\02多张' # 图片保存路径
os.makedirs(new_path,exist_ok=True)
z=5 # 份数
start_grid_num = 2 # 开始的每行格子数
grid_num = start_grid_num # 每次调用时候的每行格子数
size = 800 # 画布的大小
margin = 2 # 格子边缘大小
max_grid_num = 6 # 最大的每行格子数
# 色块颜色差
color_start=10 # 起始的色块值(最小)
color_end=50 # 结束的色块值(最大)
color_gap=10 # 最大最小色块值的间隔数量 如10个数字一次
# 开始的色块差,10的色块与其他底色相同,看不清清除,,100数字越大,对比越清晰,看的清除
start_color_gap = list(range(color_start,color_end+color_start, color_gap))
# start_color_gap = list(range(100, 0, -10)) # 为了从简单(100)到难(10),数字翻过来
# 难度,从色块颜色差里提取
nd=list(range(int(color_end/color_gap),int(color_start/color_gap)-1,-int(color_gap/color_gap)))
# (10,0,-1)
print(start_color_gap)
min_color_gap = 5 # 最小色块差
color_list = [] # 颜色列表
each_size = 0 # 每块格子的大小
A = np.full((grid_num, grid_num), 0) # 矩阵
max_color_gap = 25
def get_random_position(length):
random_x = random.randint(0, length - 1) # 随机生成x坐标
random_y = random.randint(0, length - 1) # 随机生成y坐标
return random_x, random_y
def change_color_from_rgb(rgb):
return "#%02x%02x%02x" % (rgb[0], rgb[1], rgb[2]) # 将RGB颜色转换为十六进制颜色
def color_change():
global color_list, color_gap
color_list = [] # 清空颜色列表
rgb_set1 = [random.randint(0, 255 - color_gap), random.randint(0, 255 - color_gap), random.randint(0, 255 - color_gap)] # 生成第一个颜色的RGB值
rgb_set2 = list((i + color_gap for i in rgb_set1)) # 生成第二个颜色的RGB值
color_list.append(change_color_from_rgb(rgb_set1)) # 将第一个颜色添加到颜色列表中
color_list.append(change_color_from_rgb(rgb_set2)) # 将第二个颜色添加到颜色列表中
if color_gap > min_color_gap:
color_gap -= 1 # 如果当前颜色间隔大于最小颜色间隔,则减小颜色间隔
if __name__ == '__main__':
for aa in range(z): # 每个宫格2张
for zz in range(len(start_color_gap)):
start_grid_num = 2 # 开始的每行格子数
grid_num = start_grid_num # 每次调用时候的每行格子数
for yy in range(start_grid_num, max_grid_num + 1):
color_gap = start_color_gap[zz]
print(color_gap)
A = np.full((grid_num, grid_num), 0) # 重置二维数组
each_size = size // grid_num # 计算每个网格的尺寸
s_x, s_y = get_random_position(grid_num) # 获取随机位置
A[s_x][s_y] = -1 # 将随机位置的值设为-1
img1 = Image.new('RGB', (size, size), 'lightcyan') # 创建一个新的图片对象
img2 = Image.new('RGB', (size, size), 'lightcyan') # 创建一个新的图片对象
draw1 = ImageDraw.Draw(img1) # 创建一个绘图对象
draw2 = ImageDraw.Draw(img2) # 创建一个绘图对象
color_change() # 改变颜色
for i in range(0, grid_num):
for j in range(0, grid_num):
if A[i][j] == 0:
draw1.rectangle([i * each_size + margin, j * each_size + margin, (i + 1) * each_size - margin, (j + 1) * each_size - margin], fill=color_list[0]) # 绘制矩形并填充颜色
draw2.rectangle([i * each_size + margin, j * each_size + margin, (i + 1) * each_size - margin, (j + 1) * each_size - margin], fill=color_list[0]) # 绘制矩形并填充颜色
elif A[i][j] == -1:
draw1.rectangle([i * each_size + margin, j * each_size + margin, (i + 1) * each_size - margin, (j + 1) * each_size - margin], fill=color_list[1]) # 绘制矩形并填充颜色
draw2.rectangle([i * each_size + margin, j * each_size + margin, (i + 1) * each_size - margin, (j + 1) * each_size - margin], fill=color_list[1], outline='white', width=10) # 绘制矩形并填充颜色,添加黑色边框
if grid_num <= max_grid_num:
grid_num += 1 # 如果当前网格数量小于最大网格数量,则增加网格数量
img1.save(new_path+fr'\难度{nd[zz]:02d}色彩间距{start_color_gap[zz]:03d}色块差{min_color_gap:03d}格子数{grid_num-1:02d}第{aa+1:03d}张_01试题.png') # 保存图片
img2.save(new_path+fr'\难度{nd[zz]:02d}色彩间距{start_color_gap[zz]:03d}色块差{min_color_gap:03d}格子数{grid_num-1:02d}第{aa+1:03d}张_02答案.png') # 保存图片
print('------2、导入PPT----------')
import os
from pptx import Presentation
from pptx.util import Inches
# 创建一个新的PPT文件
ppt = Presentation()
# 设置PPT页面大小为800x800
ppt.slide_width = Inches(8)
ppt.slide_height = Inches(8)
# 获取123文件夹中的所有图片文件
image_folder = new_path
image_files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg', '.gif'))]
# 将图片批量导入到PPT中
for image_file in image_files:
slide = ppt.slides.add_slide(ppt.slide_layouts[6]) # 添加一个空白幻灯片
img_path = os.path.join(image_folder, image_file)
left, top, width, height = Inches(0), Inches(0), Inches(8), Inches(8)
slide.shapes.add_picture(img_path, left, top, width, height)
# 保存PPT文件
ppt.save(path+fr'\02色块小游戏(每种{z}张{start_grid_num}-{max_grid_num}).pptx')
import shutil
shutil.rmtree(new_path)
色差50
色差10
宫格少一点,色差变化小一点(从10-100变成10-50),便于幼儿观察并说出色块方位(第X行第Y 个)