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

    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:
            
            # 随机生成矩形位置和大小
            left = random.randint(0, width - min_rect_size)
            top = random.randint(0, height - min_rect_size)
            right = left + random.randint(min_rect_size, width - left)
            bottom = top + random.randint(min_rect_size, height - top)

            # 检查新矩形是否与已放置的矩形重叠
            for rect in placed_rects:
                if left < rect[2] and right > rect[0] and top < rect[3] and bottom > rect[1]:
                    # 如果重叠,则重新生成新的矩形位置和大小
                    break
            else:
                # 如果没有重叠,则绘制矩形并添加到已放置的矩形列表
                # color = random.choice(colors)
                color =colors[_]
                outline_color = (0, 0, 0)  # 外框线颜色为黑色
                outline_width = 30 # 外框线宽度
                draw.rectangle([(left, top), (right, bottom)], fill=color, outline=(0, 0, 0),width=outline_width)
                placed_rects.append((left, top, right, bottom))
                success = True

                # 延长矩形边界至画布边框
                # 延长矩形边界至画布边框
                # draw.line([(left, top), (0, top)], fill=outline_color, width=outline_width)
                # draw.line([(right, top), (width, top)], fill=outline_color, width=outline_width)
                # draw.line([(right, bottom), (width, bottom)], fill=outline_color, width=outline_width)
                # draw.line([(left, bottom), (0, bottom)], fill=outline_color, width=outline_width)
                # draw.line([(left, top), (left, 0)], fill=outline_color, width=outline_width)
                # draw.line([(right, top), (right, 0)], fill=outline_color, width=outline_width)
                # draw.line([(right, bottom), (right, height)], fill=outline_color, width=outline_width)
                # draw.line([(left, bottom), (left, height)], fill=outline_color, width=outline_width)

            
# 检测矩形右上角的坐标(right+1、top+15),向右侧水平延伸画一根黑色线条
                
                 # 检测矩形左下角的坐标(left-1、bottom-15),向下垂直延伸画一根黑色线条
                y = extend_line_to_boundary_down(left - 1, bottom - 15, 1, outline_color, height, image)
                draw.line([(left + 15, bottom - 15), (left + 15, y)], fill=outline_color, width=outline_width)
                

                #  # 检测矩形左上角的坐标(left-1、top+15),向上垂直延伸画一根黑色线条
                y = extend_line_to_boundary_up(left-1, top+15, -1, outline_color, height, image)
                draw.line([(left +15, top + 15), (left +15, y)], fill=outline_color, width=outline_width)

                # 检测矩形左上角的坐标(left-1、top+15),向左侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_left(left -1, top + 15, -1, outline_color)
                draw.line([(left - 1, top + 15), (x, top + 15)], fill=outline_color, width=outline_width)               
            
                # 检测矩形右上角的坐标(right+1、top+15),向上垂直延伸画一根黑色线条
                y = extend_line_to_boundary_up(right + 1, top + 15, -1, outline_color, height, image)
                draw.line([(right -15, top + 15), (right -15, y)], fill=outline_color, width=outline_width)

                 # 检测矩形左下角的坐标(left-1、top+15),向左侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_left(left -1, bottom - 15, -1, outline_color)
                draw.line([(left - 1, bottom - 15), (x, bottom - 15)], fill=outline_color, width=outline_width)

            # 检测矩形右上角的坐标(right+1、top+15),向右侧水平延伸画一根黑色线条
                
                #  # 检测矩形左下角的坐标(left-1、bottom-15),向下垂直延伸画一根黑色线条
                # y = extend_line_to_boundary_down(left - 1, bottom - 15, 1, outline_color, height, image)
                # draw.line([(left + 15, bottom - 15), (left + 15, y)], fill=outline_color, width=outline_width)

                x = extend_line_to_boundary_right(right + 1, top + 15, 1, outline_color, width, image)
                draw.line([(right + 1, top + 15), (x, top + 15)], fill=outline_color, width=outline_width)              

                # 检测矩形右下角的坐标(right+1、bottom-15),向下垂直延伸画一根黑色线条
                y = extend_line_to_boundary_down(right + 1, bottom - 15, 1, outline_color, height, image)
                draw.line([(right - 15, bottom - 15), (right - 15, y)], fill=outline_color, width=outline_width)

                  # 检测矩形右下角的坐标(right+1、top+15),向右侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_right(right + 1, bottom - 15, 1, outline_color, width, image)
                draw.line([(right + 1, bottom - 15), (x, bottom - 15)], fill=outline_color, width=outline_width)     
                       
    # 显示图片(如果你使用的是图形界面环境)
    # image.show()

    image.save(fr'C:\Users\jg2yXRZ\OneDrive\桌面\蒙德里安\{xx}.png')

随机生成20张

重点说明:

A4横板打印,所以我让短一点的Y(上下方向线条)生成,然后再生成长一点X(左右方向线条),否则左右线条生成后,上下线条可能都不出现了(上线线条接触到左右方向的黑线就终止)

二、黑白蒙德里安

我的教学目的是“三原色+黑色的涂色”,所以就不要填充颜色了

修改内容(填充白色)

代码展示:

'''
目的:蒙德里安(大小不规律格子)白色
作者:AI对话大师
时间:2024年5月8日
'''

from PIL import Image, ImageDraw
import random


for xx in range(40):
    # 创建一个新的空白图片
    width, height = 2900, 2100
    min_rect_size = 100

    image = Image.new('RGB', (width, height), color=(255, 255, 255))
    draw = ImageDraw.Draw(image)

    # 已放置的矩形列表
    placed_rects = []

    # 尝试放置多个不重叠的矩形
    num_rects = 1  # 尝试放置的矩形数量
    # 控制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.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:
            
            # 随机生成矩形位置和大小
            left = random.randint(0, width - min_rect_size)
            top = random.randint(0, height - min_rect_size)
            right = left + random.randint(min_rect_size, width - left)
            bottom = top + random.randint(min_rect_size, height - top)

            # 检查新矩形是否与已放置的矩形重叠
            for rect in placed_rects:
                if left < rect[2] and right > rect[0] and top < rect[3] and bottom > rect[1]:
                    # 如果重叠,则重新生成新的矩形位置和大小
                    break
            else:
                # 如果没有重叠,则绘制矩形并添加到已放置的矩形列表
                color = random.choice(colors)  # 随机选择颜色里的一个白色
                
                outline_color = (0, 0, 0)  # 外框线颜色为黑色
                outline_width = 30 # 外框线宽度
                draw.rectangle([(left, top), (right, bottom)], fill=color, outline=(0, 0, 0),width=outline_width)
                placed_rects.append((left, top, right, bottom))
                success = True

                # 延长矩形边界至画布边框
                # 延长矩形边界至画布边框
                # draw.line([(left, top), (0, top)], fill=outline_color, width=outline_width)
                # draw.line([(right, top), (width, top)], fill=outline_color, width=outline_width)
                # draw.line([(right, bottom), (width, bottom)], fill=outline_color, width=outline_width)
                # draw.line([(left, bottom), (0, bottom)], fill=outline_color, width=outline_width)
                # draw.line([(left, top), (left, 0)], fill=outline_color, width=outline_width)
                # draw.line([(right, top), (right, 0)], fill=outline_color, width=outline_width)
                # draw.line([(right, bottom), (right, height)], fill=outline_color, width=outline_width)
                # draw.line([(left, bottom), (left, height)], fill=outline_color, width=outline_width)

            
   # 检测矩形左下角的坐标(left-1、bottom-15),向下垂直延伸画一根黑色线条
                y = extend_line_to_boundary_down(left - 1, bottom - 15, 1, outline_color, height, image)
                draw.line([(left + 15, bottom - 15), (left + 15, y)], fill=outline_color, width=outline_width)
                

                #  # 检测矩形左上角的坐标(left-1、top+15),向上垂直延伸画一根黑色线条
                y = extend_line_to_boundary_up(left-1, top+15, -1, outline_color, height, image)
                draw.line([(left +15, top + 15), (left +15, y)], fill=outline_color, width=outline_width)

                # 检测矩形左上角的坐标(left-1、top+15),向左侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_left(left -1, top + 15, -1, outline_color)
                draw.line([(left - 1, top + 15), (x, top + 15)], fill=outline_color, width=outline_width)               
            
                # 检测矩形右上角的坐标(right+1、top+15),向上垂直延伸画一根黑色线条
                y = extend_line_to_boundary_up(right + 1, top + 15, -1, outline_color, height, image)
                draw.line([(right -15, top + 15), (right -15, y)], fill=outline_color, width=outline_width)

                 # 检测矩形左下角的坐标(left-1、top+15),向左侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_left(left -1, bottom - 15, -1, outline_color)
                draw.line([(left - 1, bottom - 15), (x, bottom - 15)], fill=outline_color, width=outline_width)

            # # 检测矩形右上角的坐标(right+1、top+15),向右侧水平延伸画一根黑色线条
                
            #      # 检测矩形左下角的坐标(left-1、bottom-15),向下垂直延伸画一根黑色线条
            #     y = extend_line_to_boundary_down(left - 1, bottom - 15, 1, outline_color, height, image)
            #     draw.line([(left + 15, bottom - 15), (left + 15, y)], fill=outline_color, width=outline_width)

                x = extend_line_to_boundary_right(right + 1, top + 15, 1, outline_color, width, image)
                draw.line([(right + 1, top + 15), (x, top + 15)], fill=outline_color, width=outline_width)              

                # 检测矩形右下角的坐标(right+1、bottom-15),向下垂直延伸画一根黑色线条
                y = extend_line_to_boundary_down(right + 1, bottom - 15, 1, outline_color, height, image)
                draw.line([(right - 15, bottom - 15), (right - 15, y)], fill=outline_color, width=outline_width)

                  # 检测矩形右下角的坐标(right+1、top+15),向右侧水平延伸画一根黑色线条
                x = extend_line_to_boundary_right(right + 1, bottom - 15, 1, outline_color, width, image)
                draw.line([(right + 1, bottom - 15), (x, bottom - 15)], fill=outline_color, width=outline_width)     
                       
    # 显示图片(如果你使用的是图形界面环境)
    # image.show()

    image.save(fr'C:\Users\jg2yXRZ\OneDrive\桌面\蒙德里安\{xx}.png')

稍微选一下图片,不要让孩子涂色面积过大,影响授课时间

也可以修改图形数量12个变成5个,看看小格子是不是不见了?

特别细小的小格子数量变少了。

2个矩形

1个矩形

修改,把代码放到最上面

一个矩形的8个方向线条都有了

再把彩色的蒙德里安也修改一下,确保8个线条都生成

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

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

相关文章

ChIP-seq or CUTTag,谁能hold住蛋白质与DNA互作主战场?

DNA与蛋白质的相互作用作为表观遗传学中的一个重要领域&#xff0c;对理解基因表达调控、DNA复制与修复、表观遗传修饰&#xff08;组蛋白修饰&#xff09;及染色质结构等基本生命过程至关重要。 自1983年James Broach首次公布染色质免疫共沉淀&#xff08;ChIP&#xff09;技…

Docker-Compose 容器集群的快速编排

Docker-compose 简介 Docker-Compose项目是Docker官方的开源项目&#xff0c;负责实现对Docker容器集群的快速编排。 Docker-Compose将所管理的容器分为三层&#xff0c;分别是 工程&#xff08;project&#xff09;&#xff0c;服务&#xff08;service&#xff09;以及容器&…

LLM 安全 | 大语言模型应用安全入门

一、背景 2023年以来&#xff0c;LLM 变成了相当炙手可热的话题&#xff0c;以 ChatGPT 为代表的 LLM 的出现&#xff0c;让人们看到了无限的可能性。ChatGPT能写作&#xff0c;能翻译&#xff0c;能创作诗歌和故事&#xff0c;甚至能一定程度上做一些高度专业化的工作&#x…

滤除纹波的方法:

空载时看起来纹波比较小但是一加负载的时候纹波一下子上来是因为空载时候电流比较小MOS大部分时间处于关断状态&#xff0c;而加上负载后电流变大MOS打开关闭更为频繁&#xff0c;因而纹波更大。 下图中的尖峰可能是因为电路的寄生电感导致的&#xff0c;理论上只能削弱不能避…

LINUX 入门 8

LINUX 入门 8 day10 20240507 耗时&#xff1a;90min 有点到倦怠期了 课程链接地址 第8章 TCP服务器 1 TCP服务器的介绍 开始讲服务器端&#xff0c;之前是客户端DNShttps请求 基础&#xff1a;网络编程并发服务器&#xff1a;多客户端 一请求&#xff0c;一线程 veryold…

推荐网站(6)33台词,通过台词找电影、电视剧、纪录片等素材

今天推荐一个网站33台词&#xff0c;你可以根据电影、电视剧、纪录片等某一段台词&#xff0c;来找到来源&#xff0c;帮你精确到多少分多少秒出现的&#xff0c;非常的好用&#xff0c;尤其是对那种只记得一些经典台词&#xff0c;不知道是哪个电影的人来说&#xff0c;帮助巨…

揭秘全网热门话题:抖音快速涨粉方法,巨量千川投流助你日增10000粉

在当今社交媒体的时代( 千川投流&#xff1a;hzzxar&#xff09;抖音成为了年轻人分享自己才华和生活的平台。然而&#xff0c;要在抖音上快速获得关注和粉丝&#xff0c;却不是一件容易的事情。今天&#xff0c;我们将揭秘全网都在搜索的抖音快速涨1000粉的秘籍&#xff0c;带…

网络文件共享

存储类型分三类 直连式存储&#xff1a;DAS存储区域网络&#xff1a;SAN网络附加存储&#xff1a;NAS 三种存储架构的应用场景 DAS虽然比较古老了&#xff0c;但是还是很适用于那些数据量不大&#xff0c;对磁盘访问速度要求较高的中小企业SAN多适用于文件服务器&#xff0c…

pyfilesystem2,一个超级实用的 Python 库!

更多Python学习内容&#xff1a;ipengtao.com 大家好&#xff0c;今天为大家分享一个超级实用的 Python 库 - pyfilesystem2。 Github地址&#xff1a;https://github.com/pyfilesystem/pyfilesystem2 PyFilesystem2是一个强大的Python库&#xff0c;用于抽象化文件系统操作。它…

静态分析-RIPS-源码解析记录-02

这部分主要分析scanner.php的逻辑&#xff0c;在token流重构完成后&#xff0c;此时ini_get是否包含auto_prepend_file或者auto_append_file 取出的文件路径将和tokens数组结合&#xff0c;每一个文件都为一个包含require文件名的token数组 接着回到main.php中&#xff0c;此时…

【GUI软件】调用YouTube的API接口,采集关键词搜索结果,并封装成界面工具!

文章目录 一、背景介绍1.1 爬取目标1.2 演示视频1.3 软件说明 二、代码讲解2.1 调用API-搜索接口2.2 调用API-详情接口2.3 API_KEY说明2.4 软件界面模块2.5 日志模块 三、获取源码及软件 一、背景介绍 1.1 爬取目标 您好&#xff01;我是马哥python说&#xff0c;一名10年程序…

动态规划day.2

62.不同路径 链接&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 题目描述&#xff1a; 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#…

能否直接上手 Qt ?——看完 C++ 课本后怎么做?

在开始前我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「Qt的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;如果你已经阅读了 C 课本&#xff0c;但仍然感到…

TMS320F28335学习笔记-时钟系统

第一次使用38225使用了普中的clocksystem例程进行编译&#xff0c;总是编译失败。 问题一&#xff1a;提示找不到文件 因为工程的头文件路径没有包含&#xff0c;下图的路径需要添加自己电脑的路径。 问题二 找不到库文件 例程种的header文件夹和common文件夹不知道从何而来…

7.删除有序数组中的重复项(快慢指针)

文章目录 题目简介题目解答解法一&#xff1a;暴力解法复杂度分析&#xff1a; 解法二&#xff1a;双指针(快慢指针)代码&#xff1a;复杂度分析&#xff1a; 题目链接 大家好&#xff0c;我是晓星航。今天为大家带来的是 相关的讲解&#xff01;&#x1f600; 题目简介 题目解…

【C语言 | 字符串处理】sscanf 详细介绍、使用说明以及使用例子源码

&#x1f601;博客主页&#x1f601;&#xff1a;&#x1f680;https://blog.csdn.net/wkd_007&#x1f680; &#x1f911;博客内容&#x1f911;&#xff1a;&#x1f36d;嵌入式开发、Linux、C语言、C、数据结构、音视频&#x1f36d; ⏰发布时间⏰&#xff1a;2024-05-08 1…

【Python爬虫】使用request和xpath爬取高清美女图片

&#x1f4dd;个人主页&#xff1a;哈__ 期待您的关注 目录 &#x1f388; urlib.request &#x1f525;具体的方法 ✈ lxml &#x1f525;xpath的基本语法 1. 基本路径 2. 选择节点 3. 谓语&#xff08;Predicates&#xff09; 4. 通配符 5. 选择多个路径 6. 函数 …

OV证书——企业网站的第一选择

据官方数据统计&#xff0c;从2024年开始OV证书的签发量远远超过DV证书的签发量&#xff0c;越来越多的企业网站摒弃了基础的DV证书&#xff0c;选择更高级别的OV证书。 但是其价格相对于DV证书来说要高几百甚至上千元&#xff0c;这里推荐性价比很高的JoySSL&#xff0c;他们…

邦注科技给您解答 什么是注塑机模具保护器

模具监视器&#xff0c;这位制造业的守护神&#xff0c;时刻注视着模具的每一个细微变化。它的工作原理如同一位细心的侦探&#xff0c;利用传感器、数据采集系统和监控软件组成的精良装备&#xff0c;探寻模具的秘密。 传感器如同模具的耳目&#xff0c;敏锐地捕捉着模具的温度…

Elasticsearch的使用

Elasticsearch 1、认识和安装 Elasticsearch的官方网站如下&#xff1a; https://www.elastic.co/cn/elasticsearch Elasticsearch是由elastic公司开发的一套搜索引擎技术&#xff0c;它是elastic技术栈中的一部分。完整的技术栈包括&#xff1a; Elasticsearch&#xff1…
最新文章