作品展示

背景需求:
2年前制作了蒙德里安随机线条
【教学类-18-02】20221124《蒙德里安“红黄蓝黑格子画”-A4竖版》(大班)_蒙德里安模版-CSDN博客文章浏览阅读1k次。【教学类-18-02】20221124《蒙德里安“红黄蓝黑格子画”-A4竖版》(大班)_蒙德里安模版
https://blog.csdn.net/reasonsummer/article/details/128016371
虽然孩子们都对矩形格子涂色了,但都是N*N格子的格子涂色,

不像蒙德里安原作有“大色块小色块”的大小对比感觉(跨越两行),

这几天要上随堂课,我想就用“蒙德里安”做一个欣赏活动,全体孩子只要涂色就可以了。
一、彩色蒙德里安
测试方式:
1、一开始我尝试生成随机线条,遇到其他线条就停止,但是最终还是N*N格子的样式,填充时,整个画布都变成一种颜色。
2、后来,我准备在画布上随机生成12个黑框矩形(填充色3红3黄3蓝3黑),然后将每个矩形的左上角、右上角、左下角、右下角的位置延伸出两条黑线到画布边框(如果中途遇到黑色,就停止生成线条)
这么复杂的需求,多亏了AI对话大师,才能生成!!!
(矩形四个坐标的黑色线条延伸,问了三十几次才获得。)
代码展示:
'''
目的:蒙德里安(大小不规律格子)三原色
作者:AI对话大师
时间:2024年5月8日
'''
from PIL import Image, ImageDraw
import random
for xx in range(40):
# 创建一个新的空白图片
width, height = 2900, 2100
min_rect_size = 200
#最小边框尺寸200,方块大一点
image = Image.new('RGB', (width, height), color=(255, 255, 255))
draw = ImageDraw.Draw(image)
# 已放置的矩形列表
placed_rects = []
# 尝试放置多个不重叠的矩形
num_rects = 12 # 尝试放置的矩形数量
# 控制3个红、3个黄、3个蓝、3个黑
colors = [(255, 0, 0), (255, 0, 0), (255, 0, 0), # 红色 (3次)
(255, 255, 0), (255, 255, 0), (255, 255, 0), # 黄色 (3次)
(0, 0, 255), (0, 0, 255), (0, 0, 255), # 蓝色 (3次)
(0, 0, 0), (0, 0, 0), (0, 0, 0)] # 黑色 (3次)
# 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.getpixel((x, y)) != stop_color:
x += direction_x
return x
# 左上角向上 右上角向上
def extend_line_to_boundary_up(start_x, start_y, direction_y, stop_color, height, draw):
x = start_x
y = start_y
while 0 <= y < height:
try:
if draw.getpixel((x, y)) == stop_color:
break
except IndexError:
break
y += direction_y
return y
# 左下角向下 右下角向下
def extend_line_to_boundary_down(start_x, start_y, direction_y, stop_color, height, draw):
x = start_x
y = start_y
while 0 <= y < height:
try:
if draw.getpixel((x, y)) == stop_color:
break
except IndexError:
break
y += direction_y
return y
for _ in range(num_rects):
success = False
while not success