【教学类-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实现Excel批量样式修改器(附完整代码)

《Python实现Excel批量样式修改器(附完整代码)》这篇文章主要为大家详细介绍了如何使用Python实现一个Excel批量样式修改器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一... 目录前言功能特性核心功能界面特性系统要求安装说明使用指南基本操作流程高级功能技术实现核心技术栈关键函

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

基于C#实现PDF转图片的详细教程

《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

Python从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

使用Python实现无损放大图片功能

《使用Python实现无损放大图片功能》本文介绍了如何使用Python的Pillow库进行无损图片放大,区分了JPEG和PNG格式在放大过程中的特点,并给出了示例代码,JPEG格式可能受压缩影响,需先... 目录一、什么是无损放大?二、实现方法步骤1:读取图片步骤2:无损放大图片步骤3:保存图片三、示php

Python清空Word段落样式的三种方法

《Python清空Word段落样式的三种方法》:本文主要介绍如何用python-docx库清空Word段落样式,提供三种方法:设置为Normal样式、清除直接格式、创建新Normal样式,注意需重... 目录方法一:直接设置段落样式为"Normal"方法二:清除所有直接格式设置方法三:创建新的Normal样

Java使用Thumbnailator库实现图片处理与压缩功能

《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

Ubuntu 24.04启用root图形登录的操作流程

《Ubuntu24.04启用root图形登录的操作流程》Ubuntu默认禁用root账户的图形与SSH登录,这是为了安全,但在某些场景你可能需要直接用root登录GNOME桌面,本文以Ubuntu2... 目录一、前言二、准备工作三、设置 root 密码四、启用图形界面 root 登录1. 修改 GDM 配