【教学类-18-03】20240508《蒙德里安“红黄蓝黑格子画”-A4横版》(大小格子)

作品展示

背景需求:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿夏reasonsummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值