【教学类-55-03】20240512图层顺序挑战(三角形版)(6块三角形,420种叠放顺序)

作品展示

背景需求

分享Lab|更新啦~图层顺序挑战游戏 - 小红书 (xiaohongshu.com)icon-default.png?t=N7T8https://www.xiaohongshu.com/discovery/item/62f21760000000000900ec6d?app_platform=android&ignoreEngage=true&app_version=8.35.0&share_from_user_hidden=true&type=normal&author_share=1&xhsshare=WeixinSession&shareRedId=ODszMTs4Nk82NzUyOTgwNjg3OTlHS0xC&apptime=1715477372

数一数后发现一共有6块三角形。

第一步:设计等边三角形底板卡

小红书上的参考图是左侧边线2等分,右侧和底边4等分,

我设计等边三角形的是底边2等分,左右两侧边线4等分

'''
800图卡上制作一个等边三角形(60度内角),底边2等分(1点),左右两边4等分(3点)
作者:AI对话大师,阿夏
时间:2024年5月11日
'''
from PIL import Image, ImageDraw
import mathpath = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
# 创建800x1200的画布
canvas_width = 800
canvas_height = 800
canvas = Image.new('RGB', (canvas_width, canvas_height), color='white')
draw = ImageDraw.Draw(canvas)# 初始边长和缩放因子
initial_side_length = 250
scale_factor = 2.5# 计算等边三角形的边长
side_length = initial_side_length * scale_factor# 计算等边三角形的顶点坐标
center_x = canvas_width // 2
center_y = canvas_height // 2+130
angle = math.radians(30)  # 将角度转换为弧度
x1 = center_x - side_length // 2
y1 = center_y + int((side_length * math.sqrt(3)) / 6)
x2 = center_x + side_length // 2
y2 = y1
x3 = center_x
print(x3)
y3 = center_y - int((side_length * math.sqrt(3)) / 3)# 获取左侧边的左侧点坐标
left_side_x = x1
left_side_y = (y1 + y3) // 2# 将顶点1和顶点2的连线进行四等分
divide_1_t = 1/2
divide_2_t = 1/2 divide_1_x = x1 + (x2 - x1) * divide_1_t
divide_1_y = y1 + (y2 - y1) * divide_1_tdivide_2_x = x1 + (x2 - x1) * divide_2_t
divide_2_y = y1 + (y2 - y1) * divide_2_t# divide_3_x = x1 + (x2 - x1) * divide_3_t
# divide_3_y = y1 + (y2 - y1) * divide_3_t# 将顶点2和顶点3的连线进行四等分
divide_4_t = 1/4
divide_5_t = 1/4 * 2
divide_6_t = 1/4 * 3divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_tdivide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_tdivide_6_x = x2 + (x3 - x2) * divide_6_t
divide_6_y = y2 + (y3 - y2) * divide_6_t# 将顶点3和顶点1的连线进行四等分
divide_7_t = 1/4
divide_8_t = 1/4 * 2
divide_9_t = 1/4 * 3divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_tdivide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_tdivide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t# 绘制连线上的圆点
dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),
#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框
draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点
# 在顶点1绘制黑色圆点
draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点
draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点
draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 保存绘制好的图像
canvas.save(path + r'\triangle.png')

第二步:查找各个小圆点的坐标,以坐标为顶点,制作7个固定位置的等边三角形。

代码展示:

'''
800图卡上制作一个等边三角形(60度内角),底边2等分(1点),左右两边4等分(3点)+固定7个三角出现的位置和颜色
作者:AI对话大师,阿夏
时间:2024年5月11日
'''
from PIL import Image, ImageDraw
import mathpath = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
# 创建800x1200的画布
canvas_width = 800
canvas_height = 800
canvas = Image.new('RGB', (canvas_width, canvas_height), color='white')
draw = ImageDraw.Draw(canvas)# 初始边长和缩放因子
initial_side_length = 250
scale_factor = 2.5# 计算等边三角形的边长
side_length = initial_side_length * scale_factor# 计算等边三角形的顶点坐标
center_x = canvas_width // 2
center_y = canvas_height // 2+130
angle = math.radians(30)  # 将角度转换为弧度
x1 = center_x - side_length // 2
y1 = center_y + int((side_length * math.sqrt(3)) / 6)
x2 = center_x + side_length // 2
y2 = y1
x3 = center_x
print(x3)
y3 = center_y - int((side_length * math.sqrt(3)) / 3)# 获取左侧边的左侧点坐标
left_side_x = x1
left_side_y = (y1 + y3) // 2# 将顶点1和顶点2的连线进行四等分
divide_1_t = 1/2
divide_2_t = 1/2 divide_1_x = x1 + (x2 - x1) * divide_1_t
divide_1_y = y1 + (y2 - y1) * divide_1_tdivide_2_x = x1 + (x2 - x1) * divide_2_t
divide_2_y = y1 + (y2 - y1) * divide_2_t# divide_3_x = x1 + (x2 - x1) * divide_3_t
# divide_3_y = y1 + (y2 - y1) * divide_3_t# 将顶点2和顶点3的连线进行四等分
divide_4_t = 1/4
divide_5_t = 1/4 * 2
divide_6_t = 1/4 * 3divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_tdivide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_tdivide_6_x = x2 + (x3 - x2) * divide_6_t
divide_6_y = y2 + (y3 - y2) * divide_6_t# 将顶点3和顶点1的连线进行四等分
divide_7_t = 1/4
divide_8_t = 1/4 * 2
divide_9_t = 1/4 * 3divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_tdivide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_tdivide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t# 绘制连线上的圆点
dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),
#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框
draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点
# 在顶点1绘制黑色圆点
draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点
draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点
draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 以顶点3坐标为顶部画一个填充红色、黑色边框、大小为10的等边三角形
triangle_side_length = 470# 第1种
# 计算新等边三角形的顶点坐标
triangle_x1 = x3 - triangle_side_length // 3
triangle_y1 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)
triangle_x2 = x3 + triangle_side_length // 3
triangle_y2 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)
triangle_x3 = x3
triangle_y3 = y3# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='red')# 第2种
# 获取顶点2和顶点3连线上3/4的圆点坐标
triangle_center_x = divide_6_x
triangle_center_y = divide_6_y# 计算新等边三角形的边长
triangle_side_length = 626
# 计算新等边三角形的顶点坐标
triangle_x1 = triangle_center_x - triangle_side_length // 4
triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x2 = triangle_center_x + triangle_side_length // 4
triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x3 = triangle_center_x
triangle_y3 = triangle_center_y# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='yellow')# 第3种# 获取顶点2和顶点3连线上2/4的圆点坐标
triangle_center_x = divide_5_x
triangle_center_y = divide_5_y# 计算新等边三角形的顶点坐标
triangle_x1 = triangle_center_x - triangle_side_length // 4
triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x2 = triangle_center_x + triangle_side_length // 4
triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x3 = triangle_center_x
triangle_y3 = triangle_center_y# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='green')# 第4中种             # 获取顶点3和顶点1连线上2/4的圆点坐标
triangle_center_x = divide_8_x
triangle_center_y = divide_8_y# 计算新等边三角形的顶点坐标
triangle_x1 = triangle_center_x - triangle_side_length // 4
triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x2 = triangle_center_x + triangle_side_length // 4
triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x3 = triangle_center_x
triangle_y3 = triangle_center_y# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='blue')# 第5种            # 获取顶点3和顶点1连线上1/4的圆点坐标
triangle_center_x = divide_7_x
triangle_center_y = divide_7_y# 计算新等边三角形的顶点坐标
triangle_x1 = triangle_center_x - triangle_side_length // 4
triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x2 = triangle_center_x + triangle_side_length // 4
triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x3 = triangle_center_x
triangle_y3 = triangle_center_y# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='pink')# 第6种  
# 获取顶点1和顶点2连线上1/2的圆点坐标
triangle_center_x = divide_1_x
triangle_center_y = divide_1_y# 计算新等边三角形的顶点坐标
triangle_x1 = triangle_center_x - triangle_side_length // 4
triangle_y1 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x2 = triangle_center_x + triangle_side_length // 4
triangle_y2 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)
triangle_x3 = triangle_center_x
triangle_y3 = triangle_center_y# 绘制新等边三角形
draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', fill='purple')# 保存绘制好的图像
canvas.save(path + r'\triangle.png')

通过代码,将6个三角形的图形位置进行固定

第三步:生成不重复的6块三角形排列方式720种

将6个位置的三角形做成函数体,然后测算有多少种不同的排列顺序(显示6个图片有6*5*4*3*2*1=720个不重复排列方法)

'''
项目:图层顺序挑战(三角形版)6块等边三角形,用函数测算有不同的排列方式
作者:AI对话大师,阿夏
时间:20240511
'''
from PIL import Image, ImageDraw
import math,random,oscolors1 = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']
ss=626
w=3
# 
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
os.makedirs(path,exist_ok=True)# 创建800x1200的画布
canvas_width = 800
canvas_height = 800
canvas = Image.new('RGB', (canvas_width, canvas_height), color='white')
draw = ImageDraw.Draw(canvas)# 初始边长和缩放因子
initial_side_length = 250
scale_factor = 2.5# 计算等边三角形的边长
side_length = initial_side_length * scale_factor# 计算等边三角形的顶点坐标
center_x = canvas_width // 2
center_y = canvas_height // 2+130
angle = math.radians(30)  # 将角度转换为弧度
x1 = center_x - side_length // 2
y1 = center_y + int((side_length * math.sqrt(3)) / 6)
x2 = center_x + side_length // 2
y2 = y1
x3 = center_x   
y3 = center_y - int((side_length * math.sqrt(3)) / 3)# 获取左侧边的左侧点坐标
left_side_x = x1
left_side_y = (y1 + y3) // 2# 将顶点1和顶点2的连线进行四等分
divide_1_t = 1/2
divide_2_t = 1/2 divide_1_x = x1 + (x2 - x1) * divide_1_t
divide_1_y = y1 + (y2 - y1) * divide_1_tdivide_2_x = x1 + (x2 - x1) * divide_2_t
divide_2_y = y1 + (y2 - y1) * divide_2_t# divide_3_x = x1 + (x2 - x1) * divide_3_t
# divide_3_y = y1 + (y2 - y1) * divide_3_t# 将顶点2和顶点3的连线进行四等分
divide_4_t = 1/4
divide_5_t = 1/4 * 2
divide_6_t = 1/4 * 3divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_tdivide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_tdivide_6_x = x2 + (x3 - x2) * divide_6_t
divide_6_y = y2 + (y3 - y2) * divide_6_t# 将顶点3和顶点1的连线进行四等分
divide_7_t = 1/4
divide_8_t = 1/4 * 2
divide_9_t = 1/4 * 3divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_tdivide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_tdivide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t# 绘制连线上的圆点
dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),
#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框
draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点
# 在顶点1绘制黑色圆点
draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点
draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点
draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 以顶点3坐标为顶部画一个填充红色、黑色边框、大小为ss的等边三角形
triangle_side_length = 470def draw_triangle_1():# 获取顶点3和顶点1连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = 470# 第1种# 计算新等边三角形的顶点坐标triangle_x1 = x3 - triangle_side_length // 3triangle_y1 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x2 = x3 + triangle_side_length // 3triangle_y2 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x3 = x3triangle_y3 = y3# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[0])def draw_triangle_2():# 获取顶点2和顶点3连线上3/4的圆点坐标triangle_center_x = divide_6_xtriangle_center_y = divide_6_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[1])def draw_triangle_3():# 获取顶点2和顶点3连线上2/4的圆点坐标triangle_center_x = divide_5_xtriangle_center_y = divide_5_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[2])def draw_triangle_4():# 获取顶点3和顶点1连线上2/4的圆点坐标triangle_center_x = divide_8_xtriangle_center_y = divide_8_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[3])def draw_triangle_5():# 获取顶点3和顶点1连线上1/4的圆点坐标triangle_center_x = divide_7_xtriangle_center_y = divide_7_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[4])def draw_triangle_6():# 获取顶点1和顶点2连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[5])# for xx in range(1000):# 随机打乱函数的顺序(可能会有重复)
# functions = [draw_triangle_1, draw_triangle_2, draw_triangle_3, draw_triangle_4, draw_triangle_5, draw_triangle_6]
# random.shuffle(functions)import itertools# 定义函数列表
function_names = ['draw_triangle_1', 'draw_triangle_2', 'draw_triangle_3', 'draw_triangle_4', 'draw_triangle_5', 'draw_triangle_6']# 生成所有可能的排列,是元祖()
permutations = list(itertools.permutations(function_names))# 打印排列数量
print(f"总共有 {len(permutations)} 种不同的排列。")
# 720n=1
# 打印所有排列
for permutation in permutations:# print(permutation)# 将元组转换为函数对象列表,functions = [eval(function_name) for function_name in permutation[::-1]]# # 打印函数对象列表,一长串文字# print(functions)# [<function draw_triangle_2 at 0x000001A4B402F3A8>, <function draw_triangle_1 at 0x000001A4B402FB88>, <function draw_triangle_6 at 0x000001A4B4061288>, <function draw_triangle_3 at 0x000001A4B23C5AF8>, <function draw_triangle_4 at 0x000001A4B4061168>, <function draw_triangle_5 at 0x000001A4B40611F8>]# 运行一个7元素,就打乱一次颜色,确保color【0】抽取的颜色每次都不同colors = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']random.shuffle(colors)# 调用函数绘制等边三角形for func in functions:func()   # 绘制连线上的圆点dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点# 在顶点1绘制黑色圆点draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 保存绘制好的图像canvas.save(path + fr'\{n:03d}.png')n+=1# # 调用函数绘制等边三角形# draw_triangle_1()# draw_triangle_2()# draw_triangle_3()# draw_triangle_4()# draw_triangle_5()# draw_triangle_6()# # 保存绘制好的图像# canvas.save(path + fr'\{xx:02d}triangle.png')

720种6图的图层排列方法,全部变成图片。

存在问题:

本次图层排列需要6个颜色,而720种里有部分三角形被遮挡覆盖了,只能看到3-5个图形

第四步:检测图片上的颜色数量

检测图片上的颜色种类,如果小于8种(6种彩色+黑+白),就自动删除。

为了不存在JPG2里,

'''
项目:图层顺序挑战(三角形版)6块等边三角形,720种不同排列方式,删除不是6种颜色的图片 420种显示6个颜色的排列方式
作者:AI对话大师,阿夏
时间:20240511
'''
from PIL import Image, ImageDraw
import math,random,oscolors1 = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']
ss=626
w=3
# 
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
os.makedirs(path,exist_ok=True)# 创建800x1200的画布
canvas_width = 800
canvas_height = 800
canvas = Image.new('RGB', (canvas_width, canvas_height), color='white')
draw = ImageDraw.Draw(canvas)# 初始边长和缩放因子
initial_side_length = 250
scale_factor = 2.5# 计算等边三角形的边长
side_length = initial_side_length * scale_factor# 计算等边三角形的顶点坐标
center_x = canvas_width // 2
center_y = canvas_height // 2+130
angle = math.radians(30)  # 将角度转换为弧度
x1 = center_x - side_length // 2
y1 = center_y + int((side_length * math.sqrt(3)) / 6)
x2 = center_x + side_length // 2
y2 = y1
x3 = center_x   
y3 = center_y - int((side_length * math.sqrt(3)) / 3)# 获取左侧边的左侧点坐标
left_side_x = x1
left_side_y = (y1 + y3) // 2# 将顶点1和顶点2的连线进行四等分
divide_1_t = 1/2
divide_2_t = 1/2 divide_1_x = x1 + (x2 - x1) * divide_1_t
divide_1_y = y1 + (y2 - y1) * divide_1_tdivide_2_x = x1 + (x2 - x1) * divide_2_t
divide_2_y = y1 + (y2 - y1) * divide_2_t# divide_3_x = x1 + (x2 - x1) * divide_3_t
# divide_3_y = y1 + (y2 - y1) * divide_3_t# 将顶点2和顶点3的连线进行四等分
divide_4_t = 1/4
divide_5_t = 1/4 * 2
divide_6_t = 1/4 * 3divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_tdivide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_tdivide_6_x = x2 + (x3 - x2) * divide_6_t
divide_6_y = y2 + (y3 - y2) * divide_6_t# 将顶点3和顶点1的连线进行四等分
divide_7_t = 1/4
divide_8_t = 1/4 * 2
divide_9_t = 1/4 * 3divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_tdivide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_tdivide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t# 绘制连线上的圆点
dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),
#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框
draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点
# 在顶点1绘制黑色圆点
draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点
draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点
draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 以顶点3坐标为顶部画一个填充红色、黑色边框、大小为ss的等边三角形
triangle_side_length = 470def draw_triangle_1():# 获取顶点3和顶点1连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = 470# 第1种# 计算新等边三角形的顶点坐标triangle_x1 = x3 - triangle_side_length // 3triangle_y1 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x2 = x3 + triangle_side_length // 3triangle_y2 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x3 = x3triangle_y3 = y3# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[0])def draw_triangle_2():# 获取顶点2和顶点3连线上3/4的圆点坐标triangle_center_x = divide_6_xtriangle_center_y = divide_6_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[1])def draw_triangle_3():# 获取顶点2和顶点3连线上2/4的圆点坐标triangle_center_x = divide_5_xtriangle_center_y = divide_5_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[2])def draw_triangle_4():# 获取顶点3和顶点1连线上2/4的圆点坐标triangle_center_x = divide_8_xtriangle_center_y = divide_8_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[3])def draw_triangle_5():# 获取顶点3和顶点1连线上1/4的圆点坐标triangle_center_x = divide_7_xtriangle_center_y = divide_7_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[4])def draw_triangle_6():# 获取顶点1和顶点2连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[5])# for xx in range(1000):# 随机打乱函数的顺序(可能会有重复)
# functions = [draw_triangle_1, draw_triangle_2, draw_triangle_3, draw_triangle_4, draw_triangle_5, draw_triangle_6]
# random.shuffle(functions)import itertools# 定义函数列表
function_names = ['draw_triangle_1', 'draw_triangle_2', 'draw_triangle_3', 'draw_triangle_4', 'draw_triangle_5', 'draw_triangle_6']# 生成所有可能的排列,是元祖()
permutations = list(itertools.permutations(function_names))# 打印排列数量
print(f"总共有 {len(permutations)} 种不同的排列。")
# 720n=1
# 打印所有排列
for permutation in permutations:# print(permutation)# 将元组转换为函数对象列表,functions = [eval(function_name) for function_name in permutation[::-1]]# # 打印函数对象列表,一长串文字# print(functions)# [<function draw_triangle_2 at 0x000001A4B402F3A8>, <function draw_triangle_1 at 0x000001A4B402FB88>, <function draw_triangle_6 at 0x000001A4B4061288>, <function draw_triangle_3 at 0x000001A4B23C5AF8>, <function draw_triangle_4 at 0x000001A4B4061168>, <function draw_triangle_5 at 0x000001A4B40611F8>]# 运行一个7元素,就打乱一次颜色,确保color【0】抽取的颜色每次都不同colors = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']random.shuffle(colors)# 调用函数绘制等边三角形for func in functions:func()   # 绘制连线上的圆点dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点# 在顶点1绘制黑色圆点draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 保存绘制好的图像canvas.save(path + fr'\{n:03d}.png')n+=1# # 调用函数绘制等边三角形# draw_triangle_1()# draw_triangle_2()# draw_triangle_3()# draw_triangle_4()# draw_triangle_5()# draw_triangle_6()# # 保存绘制好的图像# canvas.save(path + fr'\{xx:02d}triangle.png')
print('------------检测生成的图片是否正好6个图片,有时候会覆盖只有3-5个图片,没有--------------')from PIL import Image
import os# 设定路径和文件名前缀
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'# 创建存储需要删除的图片文件名的列表
delete_images = []# 遍历文件夹内的所有图片
for filename in os.listdir(path):image_path = os.path.join(path, filename)image = Image.open(image_path)# 获取图片中的颜色数量color_set = set()for pixel_color in image.getdata():color_set.add(pixel_color)# 如果颜色数量小于8种,将该图片的文件名添加到删除列表中(六种彩色+黑白)if len(color_set) < 8:delete_images.append(filename)# 删除颜色少于8种的图片
for filename in delete_images:image_path = os.path.join(path, filename)os.remove(image_path)# 打印已删除的图片文件名
if len(delete_images) > 0:print("已删除以下图片:")for filename in delete_images:print(filename)
else:print("没有需要删除的图片。")# 720个不重复的里面,留下420个显示6色

生成720张,然后对所有图片进行检测,提取没有6个颜色的图片的路径,全部提取完成后,批量删除这些图片。

001-040的图片

检测需要时间:大约3分钟

删除后只有420张符号要求

前四行40个最后一个序号是078

现在获得的420个图片都是有6种三角形颜色,且排序方法都不同

第五步:为筛选出来的420张图片添加文字说明,另存为001-420.png

为了防止新生成的图片的数字名称与JPG文件夹里的筛选图片有同样的名称,图片存在JPG2文件夹里,

'''
项目:图层顺序挑战(三角形版)6块等边三角形,720种不同排列方式,420种显示6个颜色的排列方式,添加文字说明,另存为420张
作者:AI对话大师,阿夏
时间:20240511
'''
from PIL import Image, ImageDraw
import math,random,oscolors1 = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']
ss=626
w=3
# 
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
os.makedirs(path,exist_ok=True)# 创建800x1200的画布
canvas_width = 800
canvas_height = 800
canvas = Image.new('RGB', (canvas_width, canvas_height), color='white')
draw = ImageDraw.Draw(canvas)# 初始边长和缩放因子
initial_side_length = 250
scale_factor = 2.5# 计算等边三角形的边长
side_length = initial_side_length * scale_factor# 计算等边三角形的顶点坐标
center_x = canvas_width // 2
center_y = canvas_height // 2+130
angle = math.radians(30)  # 将角度转换为弧度
x1 = center_x - side_length // 2
y1 = center_y + int((side_length * math.sqrt(3)) / 6)
x2 = center_x + side_length // 2
y2 = y1
x3 = center_x   
y3 = center_y - int((side_length * math.sqrt(3)) / 3)# 获取左侧边的左侧点坐标
left_side_x = x1
left_side_y = (y1 + y3) // 2# 将顶点1和顶点2的连线进行四等分
divide_1_t = 1/2
divide_2_t = 1/2 divide_1_x = x1 + (x2 - x1) * divide_1_t
divide_1_y = y1 + (y2 - y1) * divide_1_tdivide_2_x = x1 + (x2 - x1) * divide_2_t
divide_2_y = y1 + (y2 - y1) * divide_2_t# divide_3_x = x1 + (x2 - x1) * divide_3_t
# divide_3_y = y1 + (y2 - y1) * divide_3_t# 将顶点2和顶点3的连线进行四等分
divide_4_t = 1/4
divide_5_t = 1/4 * 2
divide_6_t = 1/4 * 3divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_tdivide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_tdivide_6_x = x2 + (x3 - x2) * divide_6_t
divide_6_y = y2 + (y3 - y2) * divide_6_t# 将顶点3和顶点1的连线进行四等分
divide_7_t = 1/4
divide_8_t = 1/4 * 2
divide_9_t = 1/4 * 3divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_tdivide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_tdivide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t# 绘制连线上的圆点
dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),
#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框
draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点
# 在顶点1绘制黑色圆点
draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点
draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点
draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 以顶点3坐标为顶部画一个填充红色、黑色边框、大小为ss的等边三角形
triangle_side_length = 470def draw_triangle_1():# 获取顶点3和顶点1连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = 470# 第1种# 计算新等边三角形的顶点坐标triangle_x1 = x3 - triangle_side_length // 3triangle_y1 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x2 = x3 + triangle_side_length // 3triangle_y2 = y3 + int((triangle_side_length * math.sqrt(3)) / 3)triangle_x3 = x3triangle_y3 = y3# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[0])def draw_triangle_2():# 获取顶点2和顶点3连线上3/4的圆点坐标triangle_center_x = divide_6_xtriangle_center_y = divide_6_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[1])def draw_triangle_3():# 获取顶点2和顶点3连线上2/4的圆点坐标triangle_center_x = divide_5_xtriangle_center_y = divide_5_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[2])def draw_triangle_4():# 获取顶点3和顶点1连线上2/4的圆点坐标triangle_center_x = divide_8_xtriangle_center_y = divide_8_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[3])def draw_triangle_5():# 获取顶点3和顶点1连线上1/4的圆点坐标triangle_center_x = divide_7_xtriangle_center_y = divide_7_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y + int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[4])def draw_triangle_6():# 获取顶点1和顶点2连线上1/2的圆点坐标triangle_center_x = divide_1_xtriangle_center_y = divide_1_y# 计算新等边三角形的边长triangle_side_length = ss# 计算新等边三角形的顶点坐标triangle_x1 = triangle_center_x - triangle_side_length // 4triangle_y1 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x2 = triangle_center_x + triangle_side_length // 4triangle_y2 = triangle_center_y - int((triangle_side_length * math.sqrt(3)) / 4)triangle_x3 = triangle_center_xtriangle_y3 = triangle_center_y# 绘制新等边三角形draw.polygon([(triangle_x1, triangle_y1), (triangle_x2, triangle_y2), (triangle_x3, triangle_y3)],outline='black', width=w,fill=colors[5])# for xx in range(1000):# 随机打乱函数的顺序(可能会有重复)
# functions = [draw_triangle_1, draw_triangle_2, draw_triangle_3, draw_triangle_4, draw_triangle_5, draw_triangle_6]
# random.shuffle(functions)import itertools# 定义函数列表
function_names = ['draw_triangle_1', 'draw_triangle_2', 'draw_triangle_3', 'draw_triangle_4', 'draw_triangle_5', 'draw_triangle_6']# 生成所有可能的排列,是元祖()
permutations = list(itertools.permutations(function_names))# 打印排列数量
print(f"总共有 {len(permutations)} 种不同的排列。")
# 720n=1
# 打印所有排列
for permutation in permutations:# print(permutation)# 将元组转换为函数对象列表,functions = [eval(function_name) for function_name in permutation[::-1]]# # 打印函数对象列表,一长串文字# print(functions)# [<function draw_triangle_2 at 0x000001A4B402F3A8>, <function draw_triangle_1 at 0x000001A4B402FB88>, <function draw_triangle_6 at 0x000001A4B4061288>, <function draw_triangle_3 at 0x000001A4B23C5AF8>, <function draw_triangle_4 at 0x000001A4B4061168>, <function draw_triangle_5 at 0x000001A4B40611F8>]# 运行一个7元素,就打乱一次颜色,确保color【0】抽取的颜色每次都不同colors = ['red', 'yellow', 'blue', 'green', 'purple', 'pink']random.shuffle(colors)# 调用函数绘制等边三角形for func in functions:func()   # 绘制连线上的圆点dot_radius = 5draw.ellipse([(divide_1_x - dot_radius, divide_1_y - dot_radius),(divide_1_x + dot_radius, divide_1_y + dot_radius)], fill='black')draw.ellipse([(divide_2_x - dot_radius, divide_2_y - dot_radius),(divide_2_x + dot_radius, divide_2_y + dot_radius)], fill='black')# draw.ellipse([(divide_3_x - dot_radius, divide_3_y - dot_radius),#               (divide_3_x + dot_radius, divide_3_y + dot_radius)], fill='black')draw.ellipse([(divide_4_x - dot_radius, divide_4_y - dot_radius),(divide_4_x + dot_radius, divide_4_y + dot_radius)], fill='black')draw.ellipse([(divide_5_x - dot_radius, divide_5_y - dot_radius),(divide_5_x + dot_radius, divide_5_y + dot_radius)], fill='black')draw.ellipse([(divide_6_x - dot_radius, divide_6_y - dot_radius),(divide_6_x + dot_radius, divide_6_y + dot_radius)], fill='black')draw.ellipse([(divide_7_x - dot_radius, divide_7_y - dot_radius),(divide_7_x + dot_radius, divide_7_y + dot_radius)], fill='black')draw.ellipse([(divide_8_x - dot_radius, divide_8_y - dot_radius),(divide_8_x + dot_radius, divide_8_y + dot_radius)], fill='black')draw.ellipse([(divide_9_x - dot_radius, divide_9_y - dot_radius),(divide_9_x + dot_radius, divide_9_y + dot_radius)], fill='black')# 绘制等边三角形的边框draw.polygon([(x1, y1), (x2, y2), (x3, y3), (x1, y1)], outline='black')# 三个顶点画圆点# 在顶点1绘制黑色圆点draw.ellipse([(x1 - dot_radius, y1 - dot_radius),(x1 + dot_radius, y1 + dot_radius)], fill='black')# 在顶点2绘制黑色圆点draw.ellipse([(x2 - dot_radius, y2 - dot_radius),(x2 + dot_radius, y2 + dot_radius)], fill='black')# 在顶点3绘制黑色圆点draw.ellipse([(x3 - dot_radius, y3 - dot_radius),(x3 + dot_radius, y3 + dot_radius)], fill='black')# 保存绘制好的图像canvas.save(path + fr'\{n:03d}.png')n+=1# # 调用函数绘制等边三角形# draw_triangle_1()# draw_triangle_2()# draw_triangle_3()# draw_triangle_4()# draw_triangle_5()# draw_triangle_6()# # 保存绘制好的图像# canvas.save(path + fr'\{xx:02d}triangle.png')
print('------------检测生成的图片是否正好6个图片,有时候会覆盖只有3-5个图片,没有--------------')from PIL import Image
import os# 设定路径和文件名前缀
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'# 创建存储需要删除的图片文件名的列表
delete_images = []# 遍历文件夹内的所有图片
for filename in os.listdir(path):image_path = os.path.join(path, filename)image = Image.open(image_path)# 获取图片中的颜色数量color_set = set()for pixel_color in image.getdata():color_set.add(pixel_color)# 如果颜色数量小于8种,将该图片的文件名添加到删除列表中(六种彩色+黑白)if len(color_set) < 8:delete_images.append(filename)# 删除颜色少于8种的图片
for filename in delete_images:image_path = os.path.join(path, filename)os.remove(image_path)# 打印已删除的图片文件名
if len(delete_images) > 0:print("已删除以下图片:")for filename in delete_images:print(filename)
else:print("没有需要删除的图片。")# 720个不重复的里面,留下420个显示6色print('----3、给图片重新编序号,左上角添加数字')from PIL import Image, ImageDraw, ImageFont
import os
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg'
path2 = r'C:\Users\jg2yXRZ\OneDrive\桌面\三角重叠\jpg2'
os.makedirs(path2,exist_ok=True)
# 指定文件夹路径和要写入的文字
text = "三角形图层顺序挑战"  # 要写入的文字
n=1
# 遍历文件夹中的PNG图片
for filename in os.listdir(path):if filename.endswith('.png'):# 构建图片路径image_path = os.path.join(path, filename)# 打开图片image = Image.open(image_path)# 在图片上绘制文字# 打开图片image = Image.open(image_path)# 在图片上绘制文字draw = ImageDraw.Draw(image)font = ImageFont.truetype(r"C:\Windows\Fonts\simhei.ttf", 40)  # 指定字体和字号text_position = (200, 80)  # 文字位置text_to_write = f"{text}-{n}"  # 构建要写入的文字内容draw.text(text_position, text_to_write, font=font, fill=(0, 0, 0))  # 绘制文字并添加描边效果# 保存修改后的图片output_path = os.path.join(path2 , f"{n:03d}.png")image.save(output_path)n+=1# 关闭图片image.close()

图片上的标题文字是1,2……420(小朋友镜像视力001看成100).但是图片文件PNG的名称是001,002……420(便于排序)

结论:

1、程序获取精确的图例数量

      小红书上提供了16种参考图,经过AI和Python的提取,一共有420种图层排列方法。

2、运用图像颜色识别功能优化学具

      运用图片颜色检测的代码,获取图片内颜色的数量(等于8),从而排除不符合要求的图片(小于8),让图例的内容更精准。

3、运用批量作图功能添加数字标记

     在图片顶部批量写入文字和序号,做标记。便于整理、幼儿记录等。

后续:

420张图片比较多,如果A4一页横版24张,需要打印7.5张,

考虑如何用错版方式装订一本参考书(例如:第1张纸:第1页第31页内容,第2张纸:第2页和第30页……)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/10622.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【c++】set、map用法详解

set、map用法详解 1. 关联式容器2. 键值对2.1 &#xff1a;pair2.2&#xff1a;make_pair 3. 树形结构的关联式容器3.1&#xff1a;set构造函数find()erase()insert()count()lower_bound()upper_bound() 3.2&#xff1a;multiset3.3&#xff1a;map构造函数insert()operator[] …

【数据结构】浅谈

✨✨✨专栏&#xff1a;数据结构 &#x1f9d1;‍&#x1f393;个人主页&#xff1a;SWsunlight 目录 一、概念&#xff1a; 二、物理结构&#xff1a; 1、顺序存储结构&#xff1a; 2、链式存储结构&#xff1a; 3、数据索引存储结构: 4、数据散列存储结构&#xf…

现代制造之Cura切片

现代制造 有现代技术支撑的制造业&#xff0c;即无论是制造还是服务行业&#xff0c;添了现代两个字不过是因为有了现代科学技术的支撑&#xff0c;如发达的通信方式&#xff0c;不断发展的互联网&#xff0c;信息化程度加强了&#xff0c;因此可以为这两个行业增加了不少优势…

手把手教你用 spacy3 训练中文NER

文章目录 模型文件下载训练模型准备数据转化成 doc_bin 格式模型训练配置生成初始配置补全完整配置 开始训练 测试模型参考文献 模型文件下载 https://github.com/explosion/spacy-models/releases?qzh&expandedtrue 简单测试一下ner效果&#xff0c;发现根本不能用 训…

关于‘==’与equals的区别

我写的也不清楚&#xff0c;有兴趣的可以看这位大佬的文章链接&#xff0c;说的很清楚 https://www.cnblogs.com/Latiny/p/8099581.html#!comments 与 equals 方法 判断两个变量是否相等有两种方式&#xff1a;一种是利用 运算符&#xff0c;另一种是利用equals方法。 注意…

C#语音播报(通过CoreAudioAPI完成对扬声器的控制)

1&#xff0c;效果&#xff1a; 作用&#xff1a; 可对当前内容&#xff08;例如此例中的重量信息&#xff09;进行语音合成播报 。可设置系统扬声器音量与状态(是否静音),同时根据扬声器状态同步更新当前控件状态与值&#xff0c;实现强制PC扬声器按照指定的音量进行播报&…

MATLAB的Bar3函数调节渐变色(内附渐变色库.mat及.m文件免费下载链接)

一. colormap函数 可以使用colormap函数&#xff1a; t1[281.1,584.6, 884.3,1182.9,1485.2; 291.6,592.6,896,1197.75,1497.33; 293.8,596.4,898.6,1204.4,1506.4; 295.8,598,904.4,1209.0,1514.6];bar3(t1,1) set(gca,XTickLabel,{300,600,900,1200,1500},FontSize,10) set…

智慧园区能耗管控系统,3D可视化开发都需要哪些技术栈?

数据可视化&#xff1a; 数据可视化是将数据通过图表、图形、地图等可视化方式展示&#xff0c;使得数据更加直观、易于理解和分析。在智慧园区能耗管控系统中&#xff0c;可以使用各种图表库&#xff08;如Echarts、Highcharts&#xff09;和可视化工具&#xff08;如Tableau…

MES系统与WMS集成方法(满分100学习资料)

导语 大家好&#xff0c;我是智能仓储物流技术研习社的社长&#xff0c;老K。专注分享智能仓储物流技术、智能制造等内容。 新书《智能物流系统构成与技术实践》 完整版文件和更多学习资料&#xff0c;请球友到知识星球【智能仓储物流技术研习社】自行下载 这份文件是关于MES系…

常见排序算法——希尔排序

基本原理 希尔排序在插入排序的基础之上&#xff0c;将待排序序列分成组&#xff0c;分成 gap 个组&#xff0c;组的数量通过 length / 2 获得&#xff0c;比如6个元素的序列&#xff0c;那么就是 3 个组&#xff0c;每个组两个元素&#xff0c;然后将每个组的元素进行插入排…

ECharts系列:基本使用及配置项

目录 基本使用 配置项的写法与位置 配置项option包含属性 各个配置项属性大全 基本使用 在阅读本篇文章时请参考ECharts官网地址中的内容配合了解 首先我们知道ECharts图表中有许多类型&#xff0c;如折线图、柱状图、饼形图等&#xff0c;下面我以折线图为例讲解ECharts图…

文本检测模型 DBNet 一种基于分割算法的模型 对每个像素点进行自适应二值化,并将二值化过程与网络训练相结合 可微分二值化模块 概率图

文本检测模型 DBNet DBNet文本检测模型是一种基于分割算法的模型,其优化之处在于对每个像素点进行自适应二值化,并将二值化过程与网络训练相结合。 传统的文本检测方法通常将二值化作为一个后处理步骤,与网络训练分开进行。而DBNet则提出了一种可微分的二值化方法,即将文…

【全开源】Java同城预约月嫂服务上门服务本地服务源码APP+小程序+公众号+H5

特色功能&#xff1a; 预约服务&#xff1a;用户可以通过小程序在线预约月嫂服务&#xff0c;选择服务时间、服务类型、月嫂等信息&#xff0c;实现方便快捷的预约流程。在线咨询&#xff1a;用户可以通过小程序向月嫂或服务机构咨询相关问题&#xff0c;获得专业的解答和建议…

Linux修炼之路之基础指令(2)+shell命令及运行原理

目录 一&#xff1a;基础指令 7.rm指令 和 rmdir指令 8.*通配符 9.man指令 10.echo指令 11.cat 指令 12.cp 指令 13.mv指令 14.alias 指令 15.less more head tail wc-l 指令 16.date 时间相关的指令 17.cal指令 18. find which whereis 三个查找文件指令…

【全开源】Java俱乐部系统社区论坛商城系统源码-奔驰奥迪保时捷大众宝马等汽车俱乐部

特色功能&#xff1a; 会员中心&#xff1a;会员中心可以帮助企业更好地管理客户&#xff0c;包括设置积分商城、会员卡充值、个人汽车档案等功能&#xff0c;对不同的会员群体展开有针对性的营销&#xff0c;并维护和积累自己的粉丝群体。信息服务&#xff1a;负责定期发布新…

关于在ubuntu18.04中运行ORB_SLAM3时遇到的报错:段错误(核心已转储)的解决方法(踩坑记录)

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 一、段错误&#xff08;核心已转储&#xff09;1. 已放弃(核心已转储)(1) 问题描述(2)原因分析 二、解决方法1. 解决方法一2. 解决方法二 总结 一、段错误&#xff…

【硬件模块】ESP-01SWiFi模块基于AT指令详解(WiFi,TCP/IP,MQTT)

ESP-01S ESP-01S是由安信可科技开发的一款Wi-Fi模块。其核心处理器是ESP8266&#xff0c;该处理器在较小尺寸的封装中集成了业界领先的Tensilica L106超低功耗32位微型MCU&#xff0c;带有16位精简模式&#xff0c;主频支持80MHz和160MHz&#xff0c;并集成了Wi-Fi MAC/BB/RF/P…

Django性能之道:缓存应用与优化实战

title: Django性能之道&#xff1a;缓存应用与优化实战 date: 2024/5/11 18:34:22 updated: 2024/5/11 18:34:22 categories: 后端开发 tags: 缓存系统Redis优点Memcached优缺点Django缓存数据库优化性能监控安全实践 引言 在当今的互联网时代&#xff0c;用户对网站和应用…

一个优秀 Maven 项目,各 Model 间最佳继承设计方案

1.单一职责原则 (Single Responsibility Principle): 每个模块应该专注于执行一个清晰且明确定义的功能&#xff0c;遵循单一职责原则&#xff0c;以降低模块的复杂性。 2.高内聚性 (High Cohesion): 模块内的组件和类应该紧密相关&#xff0c;共同实现模块的目标。高内聚性…

macOS DOSBox 汇编环境搭建

正文 一、安装DOSBox 首先前往DOSBox的官网下载并安装最新版本的DOSBox。 二、下载必备的工具包 在用户目录下新建一个文件夹&#xff0c;比如 dosbox: mkdir dosbox然后下载一些常用的工具。下载好了后&#xff0c;将这些工具解压&#xff0c;重新放在 dosbox 这个文件夹…