【教学类-50-07】20240502“数一数”图片样式07:数一数(几何图案——图形有黑色外框线)

本文主要是介绍【教学类-50-07】20240502“数一数”图片样式07:数一数(几何图案——图形有黑色外框线),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

作品预览

背景需求:

幼儿操作时明显感觉到塑封纸反光,黄色很容易和背景融合,看不清楚。

【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交-CSDN博客文章浏览阅读810次,点赞33次,收藏14次。【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交https://blog.csdn.net/reasonsummer/article/details/137511583【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交-CSDN博客【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交-CSDN博客文章浏览阅读810次,点赞33次,收藏14次。【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交https://blog.csdn.net/reasonsummer/article/details/137511583【教学类-50-04】20240409“数一数”图片样式04:透明图形与边框相切,透明图形和其他透明图形相交重叠-CSDN博客文章浏览阅读765次,点赞21次,收藏29次。【教学类-50-04】20240409“数一数”图片样式04:透明图形与边框相切,透明图形和其他透明图形相交重叠https://blog.csdn.net/reasonsummer/article/details/137549122

所以我想让图形生成时,直接有一个黑色边线,便于区分图形

AI生成

1、把以下的代码复制到AI内【教学类-50-01】20240407“数一数”图片样式01:纯色图形与边框不相交,纯色图形和其他纯色图形不相交-CSDN博客

2、补充需求:几何图形轮廓线是黑色的

3、只要加上一个边框颜色,就完成了

代码展示

'''
01数一数图形(等腰三角形、椭圆2:1)有黑色边线
作者:AI对话大师、阿夏
时间:2024年4月28日 20:00
'''
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import os
import random
import time
from shapely.geometry import Polygon
from shapely.ops import cascaded_unionc = int(input('画布大小(15)\n'))
num=int(input('多少张\n'))
alp=1.0
# float(input('透明度(1.0=分开纯色)\n'))# 创建目录
output_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\数一数2\01几何框内不连接'end=output_dir+r'\02有框线'
os.makedirs(output_dir, exist_ok=True)
os.makedirs(end, exist_ok=True)# 随机生成多个等腰直角三角形
for i in range(num):# 创建画布fig, ax = plt.subplots(figsize=(c, c))ax.set_xlim([0, c])ax.set_ylim([0, c])# 随机几个图形num_triangles = random.randint(1, 5)num_square =random.randint(1, 5)num_cicle = random.randint(1, 5)num_ellipse = random.randint(1, 5)num_rectangle = random.randint(1, 5)colors = ['red', 'yellow', 'blue']shapes = []# 等腰三角形# for _ in range(num_triangles):#     while True:#         # 随机生成等腰三角形的顶点坐标#         base_point = np.random.rand(2) * c#         side_length = np.random.rand() * 2 + 1#         # 计算等腰三角形的顶点坐标#         top_point = base_point + np.array([side_length / 2, np.sqrt(3) * side_length / 2])#         height_point = base_point + np.array([side_length, 0])#         # 检查三角形是否在画布内部#         triangle = Polygon([base_point, top_point, height_point])#         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c) and not any(shape.intersects(triangle) for shape in shapes):#             break# # 随机选择颜色# color = np.random.choice(colors)# # 创建并填充等腰三角形# triangle_vertices = np.array([base_point, top_point, height_point])# triangle = Polygon(triangle_vertices)# triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color, edgecolor='black')# ax.add_patch(triangle_patch)# shapes.append(triangle)# 直角三角形# for _ in range(num_triangles):#     while True:#         # 随机生成等腰直角三角形的顶点坐标#         base_point = np.random.rand(2) * c#         side_length = np.random.rand() * 2 + 1#         # 计算等腰直角三角形的顶点坐标#         top_point = base_point + np.array([side_length, 0])#         height_point = base_point + np.array([0, side_length])#         # 检查三角形是否在画布内部#         triangle = Polygon([base_point, top_point, height_point])#         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c) and not any(shape.intersects(triangle) for shape in shapes):#             break#     # 随机选择颜色#     color = np.random.choice(colors)#     # 创建并填充等腰直角三角形#     triangle_vertices = np.array([base_point, top_point, height_point])#     triangle = Polygon(triangle_vertices)#     triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color, edgecolor='black')#     ax.add_patch(triangle_patch)#     shapes.append(triangle)# 倒置的直角三角形# import math# for _ in range(num_triangles):#     while True:#         # 随机生成等边三角形的顶点坐标#         base_point = np.random.rand(2) * c#         side_length = np.random.rand() * 2 + 1#         # 计算等边三角形的顶点坐标#         height = (math.sqrt(3) / 2) * side_length#         top_point = base_point + np.array([side_length / 2, height])#         left_point = base_point + np.array([0, height])#         right_point = base_point + np.array([side_length, height])#         # 检查三角形是否在画布内部#         triangle = Polygon([base_point, top_point, left_point])#         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point <= c) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):#             break#     # 随机选择颜色#     color = np.random.choice(colors)#     # 创建并填充等边三角形#     triangle_vertices = np.array([base_point, top_point, left_point])#     triangle = Polygon(triangle_vertices)#     triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color, edgecolor='black')#     ax.add_patch(triangle_patch)#     shapes.append(triangle)# 等边三角形import mathfor _ in range(num_triangles):while True:# 随机生成等边三角形的顶点坐标base_point = np.random.rand(2) * cside_length = np.random.rand() * 2 + 1# 计算等边三角形的顶点坐标height = side_length * math.sqrt(3) / 2top_point = base_point + np.array([side_length / 2, height])left_point = base_point + np.array([0, 0])right_point = base_point + np.array([side_length, 0])# 检查三角形是否在画布内部triangle = Polygon([left_point, right_point, top_point])if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point >= 0) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):break# 随机选择颜色color = np.random.choice(colors)# 创建并填充等边三角形triangle_vertices = np.array([left_point, right_point, top_point])triangle = Polygon(triangle_vertices)triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color, edgecolor='black')ax.add_patch(triangle_patch)shapes.append(triangle)# 随机生成正方形for _ in range(num_square):while True:# 随机生成正方形的中心点坐标center = np.random.rand(2) * c# 随机生成正方形的边长side_length = np.random.rand() * 2 + 1# 检查正方形是否在画布内部square = Polygon([(center[0]-side_length/2, center[1]-side_length/2), (center[0]+side_length/2, center[1]-side_length/2),(center[0]+side_length/2, center[1]+side_length/2), (center[0]-side_length/2, center[1]+side_length/2)])if np.all(center - side_length/2 >= 0) and np.all(center + side_length/2 <= c) and not any(shape.intersects(square) for shape in shapes):break# 随机选择颜色color = np.random.choice(colors)# 创建并填充正方形square_patch = patches.Rectangle((center[0]-side_length/2, center[1]-side_length/2), side_length, side_length, alpha=alp, facecolor=color, edgecolor='black')ax.add_patch(square_patch)shapes.append(square)# 随机生成圆形for _ in range(num_cicle):while True:# 随机生成圆形的中心点坐标center = np.random.rand(2) * c# 随机生成圆形的半径radius = np.random.rand() * 2 + 1# 检查圆形是否在画布内部circle = Polygon([(center[0]-radius, center[1]-radius), (center[0]+radius, center[1]-radius),(center[0]+radius, center[1]+radius), (center[0]-radius, center[1]+radius)])if np.all(center - radius >= 0) and np.all(center + radius <= c) and not any(shape.intersects(circle) for shape in shapes):break# 随机选择颜色color = np.random.choice(colors)# 创建并填充圆形circle_patch = patches.Circle((center[0], center[1]), radius, alpha=alp, facecolor=color, edgecolor='black')ax.add_patch(circle_patch)shapes.append(circle)# # 随机生成椭圆形(随意长宽,很容易被认为圆形)# for _ in range(num_ellipse):#     while True:#         # 随机生成椭圆形的中心点坐标#         center = np.random.rand(2) * c#         # 随机生成椭圆形的长轴和短轴#         major_axis = np.random.rand() * 2 + 1#         minor_axis = np.random.rand() * 2 + 1#         # 检查椭圆形是否在画布内部#         ellipse_vertices = []#         num_points = 100#         angle = np.linspace(0, 2 * np.pi, num_points)#         for a in angle:#             x = center[0] + major_axis / 2 * np.cos(a)#             y = center[1] + minor_axis / 2 * np.sin(a)#             ellipse_vertices.append([x, y])#         ellipse = Polygon(ellipse_vertices)#         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(#                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(#             shape.intersects(ellipse) for shape in shapes):#             break#     # 随机选择颜色#     color = np.random.choice(colors)#     # 创建并填充椭圆形#     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, alpha=alp, facecolor=color, edgecolor='black')#     ax.add_patch(ellipse_patch)#     shapes.append(ellipse)# # # 随机生成椭圆形水平的# for _ in range(num_ellipse):#     while True:#         # 随机生成椭圆形的中心点坐标#         center = np.random.rand(2) * c#         # 随机生成椭圆形的长轴和短轴#         major_axis = np.random.rand() * 2 + 1#         minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比#         # 检查椭圆形是否在画布内部#         ellipse_vertices = []#         num_points = 100#         angle = np.linspace(0, 2 * np.pi, num_points)#         for a in angle:#             x = center[0] + major_axis / 2 * np.cos(a)#             y = center[1] + minor_axis / 2 * np.sin(a)#             ellipse_vertices.append([x, y])#         ellipse = Polygon(ellipse_vertices)#         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(#                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(#             shape.intersects(ellipse) for shape in shapes):#             break#     # 随机选择颜色#     color = np.random.choice(colors)#     # 创建并填充椭圆形#     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, alpha=alp, facecolor=color, edgecolor='black')#     ax.add_patch(ellipse_patch)#     shapes.append(ellipse)#  # # 随机生成椭圆形水平的垂直的(任意角度倾斜)
#     import random#     for _ in range(num_ellipse):
#         while True:
#             # 随机生成椭圆形的中心点坐标
#             center = np.random.rand(2) * c#             # 随机生成椭圆形的长轴和短轴
#             major_axis = np.random.rand() * 2 + 1
#             minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比#             # 随机生成椭圆形的旋转角度
#             angle = np.random.rand() * 2 * np.pi#             # 检查椭圆形是否在画布内部
#             ellipse_vertices = []
#             num_points = 100
#             angle_points = np.linspace(0, 2 * np.pi, num_points)
#             for a in angle_points:
#                 x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)
#                 y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)
#                 ellipse_vertices.append([x, y])
#             ellipse = Polygon(ellipse_vertices)
#             if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
#                     center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
#                 shape.intersects(ellipse) for shape in shapes):
#                 break#         # 随机选择颜色
#         color = np.random.choice(colors)#         # 创建并填充椭圆形
#         ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), alpha=alp,
#                                         facecolor=color, edgecolor='black')
#         ax.add_patch(ellipse_patch)
#         shapes.append(ellipse)#  # # 随机生成椭圆形水平的垂直的(90和180)
#     import randomfor _ in range(num_ellipse):while True:# 随机生成椭圆形的中心点坐标center = np.random.rand(2) * c# 随机生成椭圆形的长轴和短轴major_axis = np.random.rand() * 2 + 1minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比# 随机选择椭圆形的旋转角度(90度或180度)angle = np.random.choice([np.pi / 2, np.pi])# 检查椭圆形是否在画布内部ellipse_vertices = []num_points = 100angle_points = np.linspace(0, 2 * np.pi, num_points)for a in angle_points:x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)ellipse_vertices.append([x, y])ellipse = Polygon(ellipse_vertices)if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(shape.intersects(ellipse) for shape in shapes):break# 随机选择颜色color = np.random.choice(colors)# 创建并填充椭圆形ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), alpha=alp,facecolor=color, edgecolor='black')ax.add_patch(ellipse_patch)shapes.append(ellipse)# # 随机生成长方形# for _ in range(num_rectangle):#     while True:#         # 随机生成长方形的中心点坐标#         center = np.random.rand(2) * c#         # 随机生成长方形的长和宽#         width = np.random.rand() * 2 + 1#         height = np.random.rand() * 2 + 1#         # 检查长方形是否在画布内部#         rectangle = Polygon([(center[0] - width / 2, center[1] - height / 2),#                              (center[0] + width / 2, center[1] - height / 2),#                              (center[0] + width / 2, center[1] + height / 2),#                              (center[0] - width / 2, center[1] + height / 2)])#         if np.all(center - np.array([width, height]) / 2 >= 0) and np.all(#                 center + np.array([width, height]) / 2 <= c) and not any(#             shape.intersects(rectangle) for shape in shapes):#             break#     # 随机选择颜色#     color = np.random.choice(colors)#     # 创建并填充长方形#     rectangle_patch = patches.Rectangle((center[0] - width / 2, center[1] - height / 2), width, height,#                                         alpha=alp, facecolor=color, edgecolor='black')#     ax.add_patch(rectangle_patch)#     shapes.append(rectangle)# 隐藏坐标轴ax.axis('off')# 保存图形output_path = os.path.join(end, f'{i:02d}.png')plt.savefig(output_path, dpi=200, bbox_inches='tight')# 关闭画布plt.close(fig)# 暂停3秒time.sleep(3)

终端输入

作品展示

打印展示:

感悟:

1.PDF上三种填充和黑色边框线都很鲜艳,

2.但是打印后,几何图案的黑色边框看上去更像灰色(线条很细)

3.这一套题目是图案之间不重叠,所以黑色边框还是有很大作用的。

这篇关于【教学类-50-07】20240502“数一数”图片样式07:数一数(几何图案——图形有黑色外框线)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/954653

相关文章

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

Go语言如何判断两张图片的相似度

《Go语言如何判断两张图片的相似度》这篇文章主要为大家详细介绍了Go语言如何中实现判断两张图片的相似度的两种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 在介绍技术细节前,我们先来看看图片对比在哪些场景下可以用得到:图片去重:自动删除重复图片,为存储空间"瘦身"。想象你是一个

使用Python实现base64字符串与图片互转的详细步骤

《使用Python实现base64字符串与图片互转的详细步骤》要将一个Base64编码的字符串转换为图片文件并保存下来,可以使用Python的base64模块来实现,这一过程包括解码Base64字符串... 目录1. 图片编码为 Base64 字符串2. Base64 字符串解码为图片文件3. 示例使用注意

Python实现自动化Word文档样式复制与内容生成

《Python实现自动化Word文档样式复制与内容生成》在办公自动化领域,高效处理Word文档的样式和内容复制是一个常见需求,本文将展示如何利用Python的python-docx库实现... 目录一、为什么需要自动化 Word 文档处理二、核心功能实现:样式与表格的深度复制1. 表格复制(含样式与内容)2

Macos创建python虚拟环境的详细步骤教学

《Macos创建python虚拟环境的详细步骤教学》在macOS上创建Python虚拟环境主要通过Python内置的venv模块实现,也可使用第三方工具如virtualenv,下面小编来和大家简单聊聊... 目录一、使用 python 内置 venv 模块(推荐)二、使用 virtualenv(兼容旧版 P

使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)

《使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)》字体设计和矢量图形处理是编程中一个有趣且实用的领域,通过Python的matplotlib库,我们可以轻松将字体轮廓... 目录背景知识字体轮廓的表示实现步骤1. 安装依赖库2. 准备数据3. 解析路径指令4. 绘制图形关键

c/c++的opencv实现图片膨胀

《c/c++的opencv实现图片膨胀》图像膨胀是形态学操作,通过结构元素扩张亮区填充孔洞、连接断开部分、加粗物体,OpenCV的cv::dilate函数实现该操作,本文就来介绍一下opencv图片... 目录什么是图像膨胀?结构元素 (KerChina编程nel)OpenCV 中的 cv::dilate() 函

使用Python实现调用API获取图片存储到本地的方法

《使用Python实现调用API获取图片存储到本地的方法》开发一个自动化工具,用于从JSON数据源中提取图像ID,通过调用指定API获取未经压缩的原始图像文件,并确保下载结果与Postman等工具直接... 目录使用python实现调用API获取图片存储到本地1、项目概述2、核心功能3、环境准备4、代码实现

Java实现图片淡入淡出效果

《Java实现图片淡入淡出效果》在现代图形用户界面和游戏开发中,**图片淡入淡出(FadeIn/Out)**是一种常见且实用的视觉过渡效果,它可以用于启动画面、场景切换、轮播图、提示框弹出等场景,通过... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细