背景需要
客户买了蒙德里安黑白格子7种尺寸,但是不需要学号方块,并指定要WORD
设计思路
【教学类-18-05】20241118正方形手工纸(蒙德里安-风格派-红黄蓝黑白)-CSDN博客文章浏览阅读1.3k次,点赞29次,收藏18次。【教学类-18-05】20241118正方形手工纸(蒙德里安-风格派-红黄蓝黑白)https://blog.csdn.net/reasonsummer/article/details/143864082?spm=1011.2415.3001.5331【教学类-18-04】20240508《蒙德里安“黑白格子画” 七款图案挑选》-CSDN博客文章浏览阅读1.7k次,点赞23次,收藏20次。【教学类-18-04】20240508《蒙德里安“黑白格子画” 七款图案挑选》
https://blog.csdn.net/reasonsummer/article/details/142612773?spm=1011.2415.3001.5331
参考以上两个代码,重新做一套没有方块的图片,因为重新做了,所以生成500张,便于自己挑选适合间距的图案
一、生成图片代码(生成会中断,需要生成多次)
'''
目的:蒙德里安(大小不规律格子)白色
作者:AI对话大师
时间:2024年5月8日
第一步:手选图片
目的:蒙德里安(大小不规律格子)白色 7款大小-
作者:AI对话大师
时间:2024年9月28日
修改:20250622
存在问题,可能会中断。不能直接满500张
'''
from PIL import Image, ImageDraw
import random,os
N=['01小正方',,'03半竖','04半横','02长条','05全竖','06全横','07全正']
print(len(N))
l= [[1500,1500],,[1500,2100],[2100,1500],[2900,500],[2100,2900],[2900,2100],[2100,2100]]
# # 正方
# width= 1500
# height= 1500
# # 长条
# width= 2738
# height= 520
# 半竖
# width= 1500
# height= 2100
# # 半横
# width= 2100
# height= 1500
# # 全横
# width= 2970
# height= 2100
# # 全竖
# width= 2100
# height= 2970
n=3
for w in range(len(N)):
outline_width = 30 # 外框线宽度
for xx in range(500):
# 创建一个新的空白图片
# width, height = 2100, 1500
min_rect_size = 200
width=int(l[w][0])
height=int(l[w][1])
image = Image.new('RGB', (width, height), color=(255, 255, 255))
draw = ImageDraw.Draw(image)
# 已放置的矩形列表
placed_rects = []
# 尝试放置多个不重叠的矩形
num_rects = n # 尝试放置的矩形数量
# colors = [(255, 0, 0), (255, 0, 0), # 红色 (3次)
# (255, 255, 0), (255, 255, 0), # 黄色 (3次)
# (0, 0, 255), (0, 0, 255), # 蓝色 (3次)
# (0, 0, 0), (0, 0, 0)] # 黑色 (3次)
# 控制3个红、3个黄、3个蓝、3个黑
colors = [(255, 255, 255)] # 白色
# colors = [(255, 0, 0), (255, 255, 0), (0, 0, 255), (0, 0, 0),(255, 255, 255)] # 颜色列表
# 左上角向左 左下角向左
def extend_line_to_boundary_left(start_x, start_y, direction_x, stop_color):
x = start_x
y = start_y
while 0 <= x <= width and image.getpixel((x, y)) != stop_color:
x += direction_x
return x
# 右上角向右 右下角向右
def extend_line_to_boundary_right(start_x, start_y, direction_x, stop_color, width, image):
x = start_x
y = start_y
while 0 <= x < width and image.getpixe