【教学类-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 math

path = 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_t

divide_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 * 3

divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_t

divide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_t

divide_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 * 3

divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_t

divide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_t

divide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t

# 绘制连线上的圆点
dot_radius = 5

draw.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 math

path = 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_t

divide_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 * 3

divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_t

divide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_t

divide_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 * 3

divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_t

divide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_t

divide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t

# 绘制连线上的圆点
dot_radius = 5

draw.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,os

colors1 = ['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_t

divide_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 * 3

divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_t

divide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_t

divide_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 * 3

divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_t

divide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_t

divide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t

# 绘制连线上的圆点
dot_radius = 5

draw.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 = 470

def draw_triangle_1():
    # 获取顶点3和顶点1连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    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', width=w,fill=colors[0])

def draw_triangle_2():
        # 获取顶点2和顶点3连线上3/4的圆点坐标
    triangle_center_x = divide_6_x
    triangle_center_y = divide_6_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[1])

def draw_triangle_3():
    # 获取顶点2和顶点3连线上2/4的圆点坐标
    triangle_center_x = divide_5_x
    triangle_center_y = divide_5_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[2])

def draw_triangle_4():
    # 获取顶点3和顶点1连线上2/4的圆点坐标
    triangle_center_x = divide_8_x
    triangle_center_y = divide_8_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[3])

def draw_triangle_5():
    # 获取顶点3和顶点1连线上1/4的圆点坐标
    triangle_center_x = divide_7_x
    triangle_center_y = divide_7_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[4])

def draw_triangle_6():
    # 获取顶点1和顶点2连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', 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)} 种不同的排列。")
# 720

n=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 = 5

    draw.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,os

colors1 = ['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_t

divide_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 * 3

divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_t

divide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_t

divide_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 * 3

divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_t

divide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_t

divide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t

# 绘制连线上的圆点
dot_radius = 5

draw.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 = 470

def draw_triangle_1():
    # 获取顶点3和顶点1连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    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', width=w,fill=colors[0])

def draw_triangle_2():
        # 获取顶点2和顶点3连线上3/4的圆点坐标
    triangle_center_x = divide_6_x
    triangle_center_y = divide_6_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[1])

def draw_triangle_3():
    # 获取顶点2和顶点3连线上2/4的圆点坐标
    triangle_center_x = divide_5_x
    triangle_center_y = divide_5_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[2])

def draw_triangle_4():
    # 获取顶点3和顶点1连线上2/4的圆点坐标
    triangle_center_x = divide_8_x
    triangle_center_y = divide_8_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[3])

def draw_triangle_5():
    # 获取顶点3和顶点1连线上1/4的圆点坐标
    triangle_center_x = divide_7_x
    triangle_center_y = divide_7_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[4])

def draw_triangle_6():
    # 获取顶点1和顶点2连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', 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)} 种不同的排列。")
# 720

n=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 = 5

    draw.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,os

colors1 = ['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_t

divide_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 * 3

divide_4_x = x2 + (x3 - x2) * divide_4_t
divide_4_y = y2 + (y3 - y2) * divide_4_t

divide_5_x = x2 + (x3 - x2) * divide_5_t
divide_5_y = y2 + (y3 - y2) * divide_5_t

divide_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 * 3

divide_7_x = x3 + (x1 - x3) * divide_7_t
divide_7_y = y3 + (y1 - y3) * divide_7_t

divide_8_x = x3 + (x1 - x3) * divide_8_t
divide_8_y = y3 + (y1 - y3) * divide_8_t

divide_9_x = x3 + (x1 - x3) * divide_9_t
divide_9_y = y3 + (y1 - y3) * divide_9_t

# 绘制连线上的圆点
dot_radius = 5

draw.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 = 470

def draw_triangle_1():
    # 获取顶点3和顶点1连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    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', width=w,fill=colors[0])

def draw_triangle_2():
        # 获取顶点2和顶点3连线上3/4的圆点坐标
    triangle_center_x = divide_6_x
    triangle_center_y = divide_6_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[1])

def draw_triangle_3():
    # 获取顶点2和顶点3连线上2/4的圆点坐标
    triangle_center_x = divide_5_x
    triangle_center_y = divide_5_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[2])

def draw_triangle_4():
    # 获取顶点3和顶点1连线上2/4的圆点坐标
    triangle_center_x = divide_8_x
    triangle_center_y = divide_8_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[3])

def draw_triangle_5():
    # 获取顶点3和顶点1连线上1/4的圆点坐标
    triangle_center_x = divide_7_x
    triangle_center_y = divide_7_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', width=w,fill=colors[4])

def draw_triangle_6():
    # 获取顶点1和顶点2连线上1/2的圆点坐标
    triangle_center_x = divide_1_x
    triangle_center_y = divide_1_y

    # 计算新等边三角形的边长
    triangle_side_length = ss

    # 计算新等边三角形的顶点坐标
    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', 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)} 种不同的排列。")
# 720

n=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 = 5

    draw.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页……)

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

类和对象中篇

类的六个默认成员函数 如果一个类中什么成员都没有&#xff0c;简称为空类。空类中什么都没有吗&#xff1f;并不是的&#xff0c;任何一个类在我们不写的情况下&#xff0c;都会自动生成下面6个默认成员函数 ①初始化和清理&#xff1a;构造函数和析构函数 ②拷贝复制&#x…

使用docker安装seafile

使用docker安装seafile 1 介绍seafile Seafile 是一款开源的企业云盘&#xff0c;支持全平台&#xff08;浏览器、Windows、Mac、Linux、Android、IPhone等&#xff09;客户端。Seafile 内置协同文档 SeaDoc &#xff0c;让协作撰写、管理和发布文档更便捷。最重要的这是国产…

3588 pwm android12 的操作

问题&#xff1a; 客户需要在android12 的界面上操作板卡上的 PWM 蜂鸣器设备。 过程&#xff1a; 1 了解一下 3588 android12 源码的 关于PWM 的驱动。 设备树找不到 pwm 但是&#xff0c; 还不知道&#xff0c;android12 最终包含的 设备树是哪个&#xff0c;但是经过我的…

Ansible主机清单与playbook 剧本

一、inventory 主机清单 Inventory支持对主机进行分组&#xff0c;每个组内可以定义多个主机&#xff0c;每个主机都可以定义在任何一个或多个主机组内。 如果是名称类似的主机&#xff0c;可以使用列表的方式标识各个主机。 vim /etc/ansible/hosts [webservers] 192.168.80.…

python零基础知识 - 定义列表的三种方式,循环列表索引值

这一小节&#xff0c;我们将从零基础的角度看一下&#xff0c;python都有哪些定义列表的方式&#xff0c;并且循环这个列表的时候&#xff0c;怎么循环&#xff0c;怎么循环他的索引值&#xff0c;怎么拿到的就是元素值。 说完循环&#xff0c;我们会说一说关键的break和contin…

基于SpringBoot+Vue社区老人健康信息管理系统

摘 要 如今社会上各行各业&#xff0c;都喜欢用自己行业的专属软件工作&#xff0c;互联网发展到这个时候&#xff0c;人们已经发现离不开了互联网。新技术的产生&#xff0c;往往能解决一些老技术的弊端问题。因为传统社区老人健康信息管理系统信息管理难度大&#xff0c;容错…

javatest

day4 2. public class test {public static void main(String[] args) {Scanner sc new Scanner(System.in);System.out.println("**************");System.out.println("存期 年利率");System.out.println("一年 2.25");System.ou…

【Python超详细的学习笔记】Python超详细的学习笔记,涉及多个领域,是个很不错的笔记

获取笔记链接 Python超详细的学习笔记 一&#xff0c;逆向加密模块 1&#xff0c;Python中运行JS代码 1.1 解决中文乱码或者报错问题 import subprocess from functools import partial subprocess.Popen partial(subprocess.Popen, encodingutf-8) import execjs1.2 常用…

Oracle SQL优化案例-查询Null值走索引

网友发来一个SQL&#xff0c;说他们公司的一个SQL要优化帮忙看一下&#xff0c;执行计划如下&#xff1a; -------------------------------------SELECT * FROM (SELECT * FROM TXS C WHERE C.A ISNULL OR C.A ORDER BY ID_TXS DESC) WHERE ROWNUM<100​---------------…

JVM---垃圾回收

目录 一、C/C的内存管理 二、Java的内存管理 三、垃圾回收的对比 四、Java的内存管理和自动垃圾回收 五、方法区的回收 手动触发回收 六、堆回收 如何判断堆上的对象可以回收&#xff1f; 引用计数法 可达性分析算法 五种对象引用 软引用 软引用的使用场景-缓存 弱引用 虚…

【深入理解MySQL的索引数据结构】

文章目录 &#x1f50a;博主介绍&#x1f964;本文内容&#x1f4d5;索引底层数据结构与算法&#x1f4d9;索引数据结构&#x1f4d8;二叉树&#x1f4d8;红黑树&#x1f4d8;Hash&#x1f4d8;B-Tree&#x1f4d8;BTree &#x1f4d9;表在不同存储引擎的存储结构&#x1f4d8;…

2023.5.12 第43周周报

学习时间&#xff1a;2023.5.5-2023.5.12 学习内容&#xff1a; 1、answer question: img&#xff1a; 看到有论文说应该让图像和文本的潜在嵌入具有相似和合理的数值范围【-2&#xff0c;2】 调试发现模型的文本图像的潜在嵌入虽然符合&#xff0c;但相差较大。 在将文本和…

Python - 深度学习系列33 - ollama_langchain_ppt生成

说明 只是为了速记一下这个实践过程。整体上说&#xff0c;这个结果并不是那么好用&#xff0c;但有一些可以借鉴的地方。 先看结果&#xff1a; 生成的PPT 说的直白点&#xff0c;就是用大模型生成了一堆没太有意义的文字&#xff0c;然后做成ppt。所以实用是不成的&#…

数据猎手:使用Java和Apache HttpComponents库下载Facebook图像

引言 在信息驱动的时代&#xff0c;互联网上的数据成为了无可比拟的宝藏。本文旨在探讨如何通过利用Java和Apache HttpComponents库&#xff0c;从全球最大的社交网络平台Facebook上获取图像数据。 作为全球最大的社交网络平台&#xff0c;Facebook聚集了数以亿计的用户&#…

Rust的协程机制:原理与简单示例

在现代编程中&#xff0c;协程&#xff08;Coroutine&#xff09;已经成为实现高效并发的重要工具。Rust&#xff0c;作为一种内存安全的系统编程语言&#xff0c;也采用了协程作为其并发模型的一部分。本文将深入探讨Rust协程机制的实现原理&#xff0c;并通过一个简单的示例来…

百度GL地图实现某一段路的路况(new BMapGL.DrivingRouteLine)

功能描述&#xff1a; 1.百度地图实现点击地图出现起点&#xff0c;再次点击出现终点&#xff08;起点终点能拖动&#xff09;绘制完终点后获取该路的路况并且起点和终点可以拖动实现实时更新&#xff08;新绘制的路段的&#xff09;路况 2.地点搜索 效果如下&#xff1a; 关键…

从文本日志到图形日志 图形化编程桌面产品的突破

在一个宽敞明亮的会议室里&#xff0c;阳光透过落地窗洒在会议桌上。卧龙和凤雏相对而坐&#xff0c;他们的面前摆放着一些关于图形化编程桌面产品的资料和测试报告。会议室里的气氛紧张而热烈&#xff0c;团队成员们围坐在一起&#xff0c;专注地倾听着卧龙和凤雏的讨论。 卧龙…

Rust编程语言的特点及其适合做什么

Rust编程语言的特点 Rust是一门系统级编程语言&#xff0c;它有如下特点。 1. 类C的语言语法 Rust的具体语法和C/C类似&#xff0c;都是由花括号限定代码块&#xff0c;还有一样的控制流关键字&#xff0c;例如if、else、while和for。然而&#xff0c;也并非所有的C或者C关键…

阿里云和AWS负载均衡服务对比分析

在云计算时代,负载均衡作为一种关键的网络基础设施,承担着在多个服务器之间分发网络流量的重要任务。作为全球两大主要的云服务提供商,阿里云和Amazon Web Services(AWS)都提供了强大的负载均衡解决方案。本文将从性能、功能、可用性和成本等方面对两者进行对比分析。我们九河云…

云南区块链商户平台:抓包技术自制开票工具(三)

前言 上节我们将登录的流程梳理完毕了&#xff0c;来到了本章重点&#xff0c;既然开发票就肯定要有以下参数&#xff1a; 原工具不支持识别历史记录&#xff0c;对于我们的小商店来说&#xff0c;开票的公司基本就是固定的几个&#xff0c;如果提供下拉支持选择将会大大降低…