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

相关文章

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

uva 10387 Billiard(简单几何)

题意是一个球从矩形的中点出发,告诉你小球与矩形两条边的碰撞次数与小球回到原点的时间,求小球出发时的角度和小球的速度。 简单的几何问题,小球每与竖边碰撞一次,向右扩展一个相同的矩形;每与横边碰撞一次,向上扩展一个相同的矩形。 可以发现,扩展矩形的路径和在当前矩形中的每一段路径相同,当小球回到出发点时,一条直线的路径刚好经过最后一个扩展矩形的中心点。 最后扩展的路径和横边竖边恰好组成一个直

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

poj 3304 几何

题目大意:给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!。 解题思路:如果存在这样的直线,过投影相交点(或投影相交区域中的点)作直线的垂线,该垂线(也是直线)必定与每条线段相交,问题转化为问是否存在一条直线和所有线段相交。 若存在一条直线与所有线段相交,此时该直线必定经过这些线段的某两个端点,所以枚举任意两个端点即可。

POJ 2318 几何 POJ 2398

给出0 , 1 , 2 ... n 个盒子, 和m个点, 统计每个盒子里面的点的个数。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y

poj 2653 几何

按顺序给一系列的线段,问最终哪些线段处在顶端(俯视图是完整的)。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y ;Point(){}Po

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk