• 【教学类-64-04】20240619彩色鱼骨图(一)6.5*1CM 6根棒子720种


    背景需求:

    幼儿益智早教玩具❗️鱼骨拼图 - 小红书在家也能自制的木棒鱼骨拼图,你也收藏起来试一试吧。 #母婴育儿 #新手爸妈 #玩具 #宝宝玩具怎么选 #早教 #早教玩具 #幼儿早教 #益智早教 #玩具 #宝宝早教 #益智拼图 #宝宝拼图 #玩不腻的益智玩具 #儿童益智桌游 #早教日常 #益智玩具 #玩具推荐icon-default.png?t=N7T8https://www.xiaohongshu.com/discovery/item/65f6e28e000000000d00dfb6?app_platform=android&ignoreEngage=true&app_version=8.40.0&share_from_user_hidden=true&xsec_source=app_share&type=video&xsec_token=CBdYq1lS_6_4JwSht55RRS6a0Us2oO80T58vVXzFTNLcI=&author_share=1&xhsshare=WeixinSession&shareRedId=ODszMTs4Nk82NzUyOTgwNjg3OTlHS0xC&apptime=1718805172&share_id=d7d2836a6bf8482fa9d9a16a71418e15

    显示用六根彩色冰棍棒做排序,淘宝上有三款尺寸的彩色冰棍棒。

    我先做一套6.5*1CM的鱼骨图

    素材准备

    代码展示

    1. '''
    2. 冰棍棒六色720种 鱼骨图 红橙黄绿蓝紫(短款)6.5*1(长款) 11.5*1 大号(15*1.8)
    3. 时间:2024年6月18日
    4. 作者:星火讯飞 阿夏
    5. '''
    6. from PIL import Image, ImageDraw
    7. import os
    8. from PIL import ImageFont
    9. path=r'C:\Users\jg2yXRZ\OneDrive\桌面\鱼骨图'
    10. new_path=path+r'\01jpg(6.5乘1)'
    11. os.makedirs(new_path,exist_ok=True)
    12. name='6.5乘1'
    13. print('-----1、制作图卡--------')
    14. # 六色所有排序方式 720种
    15. import itertools
    16. colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
    17. # 使用itertools.permutations生成所有不重复排序方式
    18. perms = list(itertools.permutations(colors))
    19. # 打乱
    20. # random.shuffle(perms)
    21. # print(perms)
    22. a=len(perms)
    23. # 720个不重复的方法
    24. # 720有几位数(个数)
    25. num_digits = len(str(a))
    26. print(num_digits)
    27. # 720就是3位数
    28. for a in range(len(perms)):
    29. # 打开图片
    30. image = Image.open(path+r'\鱼骨图.jpg')
    31. # 创建一个800*600的画布
    32. long=844
    33. wide=378
    34. s=6
    35. # 6根棒子
    36. canvas = Image.new('RGB', (long, wide), 'white')
    37. draw = ImageDraw.Draw(canvas)
    38. # 定义圆角矩形的参数
    39. # 棒子的圆心
    40. radius = 20
    41. # 左侧间距
    42. left = 220
    43. # 右侧间距
    44. right = 180
    45. # 棒子的间距
    46. padding = 30
    47. # 棒子的宽
    48. rect_width = float((long-left-right-padding*7)/6)
    49. print(rect_width)
    50. # 40
    51. # 棒子的高
    52. rect_height = float(rect_width*6.5)
    53. # 棒子的高度坐标
    54. padding2=float((wide- rect_height-20))
    55. # wide-padding*2
    56. # 计算每个圆角矩形的位置
    57. rect_positions = [
    58. (padding+left, padding2),
    59. (rect_width + padding * 2+left, padding2),
    60. (rect_width * 2 + padding * 3+left, padding2),
    61. (rect_width * 3 + padding * 4+left, padding2),
    62. (rect_width * 4 + padding * 5+left, padding2),
    63. (rect_width * 5 + padding * 6+left, padding2)
    64. ]
    65. colors = perms[a]
    66. # 绘制圆角矩形
    67. draw = ImageDraw.Draw(image)
    68. # 绘制圆角矩形
    69. for i, position in enumerate(rect_positions):
    70. x, y = position
    71. draw.rounded_rectangle([x, y, x + rect_width, y + rect_height], radius, fill=colors[i], outline='black', width=1)
    72. # 设置字体路径和大小
    73. font_path = r'C:\Windows\Fonts\AdobeHeitiStd-Regular.otf'
    74. font_size = 40
    75. # 加载字体
    76. font = ImageFont.truetype(font_path, font_size)
    77. # 在指定位置绘制文字
    78. draw.text((200, 30), f'彩色鱼骨图({name}CM)-{a+1:03d}', font=font, fill='black')
    79. # 保存图片
    80. image.save(new_path + fr'\{a+1:0{num_digits}d}.png')
    81. print('-----2、制作大图--------')
    82. # 六色所有排序方式 720种
    83. # 使用itertools.permutations生成所有不重复排序方式
    84. from PIL import Image, ImageDraw
    85. import itertools
    86. path = r'C:\Users\jg2yXRZ\OneDrive\桌面\鱼骨图'
    87. new_path_jpg = path + r'\02jpg(6.5乘1)'
    88. os.makedirs(new_path_jpg, exist_ok=True)
    89. name = '6.5乘1'
    90. for b in range(2):
    91. image = Image.open(path + r'\鱼骨图.jpg')
    92. long = 844
    93. wide = 378
    94. s = 6
    95. canvas = Image.new('RGB', (long, wide), 'white')
    96. draw = ImageDraw.Draw(canvas)
    97. radius = 20
    98. left = 220
    99. right = 180
    100. padding = 30
    101. rect_width = float((long - left - right - padding * 7) / 6)
    102. print(rect_width)
    103. rect_height = float(rect_width * 6.5)
    104. padding2 = float((wide - rect_height - 20))
    105. rect_positions = [
    106. (padding + left, padding2),
    107. (rect_width + padding * 2 + left, padding2),
    108. (rect_width * 2 + padding * 3 + left, padding2),
    109. (rect_width * 3 + padding * 4 + left, padding2),
    110. (rect_width * 4 + padding * 5 + left, padding2),
    111. (rect_width * 5 + padding * 6 + left, padding2)
    112. ]
    113. colors = perms[a]
    114. draw = ImageDraw.Draw(image)
    115. # 绘制圆角矩形
    116. for i, position in enumerate(rect_positions):
    117. x, y = position
    118. draw.rounded_rectangle([x, y, x + rect_width, y + rect_height], radius, fill='white', outline='black', width=1)
    119. # 设置字体路径和大小
    120. font_path = r'C:\Windows\Fonts\AdobeHeitiStd-Regular.otf'
    121. font_size = 40
    122. # 加载字体
    123. font = ImageFont.truetype(font_path, font_size)
    124. # 在指定位置绘制文字
    125. draw.text((150, 30), f'彩色鱼骨图({name}CM)-操作图{b+1}', font=font, fill='black')
    126. # 保存图片
    127. # image.save(new_path + fr'\{a+1:0{num_digits}d}.png')
    128. image.save(new_path_jpg + fr'\鱼骨图{name}_大图{b+1}.png')
    129. print('-----3、图卡制作成图片格式----------')
    130. import os
    131. import random
    132. from docx import Document
    133. from docx.shared import Cm
    134. from docx2pdf import convert
    135. from PyPDF2 import PdfFileMerger
    136. new_folder = path + r'\零时文件夹'
    137. os.makedirs(new_folder, exist_ok=True)
    138. image_files = [os.path.join(new_path, file) for file in os.listdir(new_path) if file.endswith('.png')]
    139. # random.shuffle(image_files)
    140. grouped_files = [image_files[i:i + 6] for i in range(0, len(image_files), 6)]
    141. for group_index, group in enumerate(grouped_files):
    142. doc = Document(path + r'\鱼骨图题卡.docx')
    143. table = doc.tables[0]
    144. for cell_index, image_file in enumerate(group):
    145. cell = table.cell(int(cell_index / 2), cell_index % 2)
    146. cell_paragraph = cell.paragraphs[0]
    147. cell_paragraph.clear()
    148. run = cell_paragraph.add_run()
    149. run.add_picture(image_file, width=Cm(13.92), height=Cm(6.49))
    150. doc.save(os.path.join(new_folder, f'{group_index + 1:03d}.docx'))
    151. pdf_output_path = path + fr'\\鱼骨图({name})题卡{len(perms)}张_固定顺序.pdf'
    152. # pdf_output_path = path + fr'\\鱼骨图({name})题卡{len(perms)}张_随机顺序.pdf'
    153. for docx_file in os.listdir(new_folder):
    154. if docx_file.endswith('.docx'):
    155. docx_path = os.path.join(new_folder, docx_file)
    156. convert(docx_path, docx_path.replace('.docx', '.pdf'))
    157. merger = PdfFileMerger()
    158. for pdf_file in os.listdir(new_folder):
    159. if pdf_file.endswith('.pdf'):
    160. pdf_path = os.path.join(new_folder, pdf_file)
    161. merger.append(pdf_path)
    162. merger.write(pdf_output_path)
    163. merger.close()
    164. import shutil
    165. shutil.rmtree(new_folder)
    166. print('-----3、图卡制作成图片格式----------')
    167. import os
    168. import random
    169. from docx import Document
    170. from docx.shared import Cm
    171. from docx2pdf import convert
    172. from PyPDF2 import PdfFileMerger
    173. new_folder = path + r'\零时文件夹'
    174. os.makedirs(new_folder, exist_ok=True)
    175. image_files = [os.path.join(new_path, file) for file in os.listdir(new_path_jpg) if file.endswith('.png')]
    176. # random.shuffle(image_files)
    177. grouped_files = [image_files[i:i + 2] for i in range(0, len(image_files), 2)]
    178. for group_index, group in enumerate(grouped_files):
    179. doc = Document(path + r'\鱼骨图操作图.docx')
    180. table = doc.tables[0]
    181. for cell_index, image_file in enumerate(group):
    182. cell = table.cell(int(cell_index / 1), cell_index % 1)
    183. cell_paragraph = cell.paragraphs[0]
    184. cell_paragraph.clear()
    185. run = cell_paragraph.add_run()
    186. run.add_picture(image_file, width=Cm(21.62), height=Cm(9.7))
    187. doc.save(os.path.join(new_folder, f'{group_index + 1:03d}.docx'))
    188. pdf_output_path = path + fr'\\鱼骨图({name})操作卡2张_固定顺序.pdf'
    189. # pdf_output_path = path + fr'\\鱼骨图({name})操作卡2张_随机顺序.pdf'
    190. for docx_file in os.listdir(new_folder):
    191. if docx_file.endswith('.docx'):
    192. docx_path = os.path.join(new_folder, docx_file)
    193. convert(docx_path, docx_path.replace('.docx', '.pdf'))
    194. merger = PdfFileMerger()
    195. for pdf_file in os.listdir(new_folder):
    196. if pdf_file.endswith('.pdf'):
    197. pdf_path = os.path.join(new_folder, pdf_file)
    198. merger.append(pdf_path)
    199. merger.write(pdf_output_path)
    200. merger.close()
    201. import shutil
    202. shutil.rmtree(new_folder)

    第一步第二步生成结果(按照正序排列)

    因为正序排列的顺序会比较相近,所以可以加上乱序

    1. '''
    2. 冰棍棒六色720种 鱼骨图 红橙黄绿蓝紫(短款)6.5*1(长款) 11.5*1 大号(15*1.8) -乱序
    3. 时间:2024年6月18日
    4. 作者:星火讯飞 阿夏
    5. '''
    6. from PIL import Image, ImageDraw
    7. import os,random
    8. from PIL import ImageFont
    9. path=r'C:\Users\jg2yXRZ\OneDrive\桌面\鱼骨图'
    10. new_path=path+r'\01jpg(6.5乘1)'
    11. os.makedirs(new_path,exist_ok=True)
    12. name='6.5乘1'
    13. print('-----1、制作图卡--------')
    14. # 六色所有排序方式 720种
    15. import itertools
    16. colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
    17. # 使用itertools.permutations生成所有不重复排序方式
    18. perms = list(itertools.permutations(colors))
    19. # 打乱
    20. random.shuffle(perms)
    21. print(perms)
    22. a=len(perms)
    23. # 720个不重复的方法
    24. # 720有几位数(个数)
    25. num_digits = len(str(a))
    26. print(num_digits)
    27. # 720就是3位数
    28. for a in range(len(perms)):
    29. # 打开图片
    30. image = Image.open(path+r'\鱼骨图.jpg')
    31. # 创建一个800*600的画布
    32. long=844
    33. wide=378
    34. s=6
    35. # 6根棒子
    36. canvas = Image.new('RGB', (long, wide), 'white')
    37. draw = ImageDraw.Draw(canvas)
    38. # 定义圆角矩形的参数
    39. # 棒子的圆心
    40. radius = 20
    41. # 左侧间距
    42. left = 220
    43. # 右侧间距
    44. right = 180
    45. # 棒子的间距
    46. padding = 30
    47. # 棒子的宽
    48. rect_width = float((long-left-right-padding*7)/6)
    49. print(rect_width)
    50. # 40
    51. # 棒子的高
    52. rect_height = float(rect_width*6.5)
    53. # 棒子的高度坐标
    54. padding2=float((wide- rect_height-20))
    55. # wide-padding*2
    56. # 计算每个圆角矩形的位置
    57. rect_positions = [
    58. (padding+left, padding2),
    59. (rect_width + padding * 2+left, padding2),
    60. (rect_width * 2 + padding * 3+left, padding2),
    61. (rect_width * 3 + padding * 4+left, padding2),
    62. (rect_width * 4 + padding * 5+left, padding2),
    63. (rect_width * 5 + padding * 6+left, padding2)
    64. ]
    65. colors = perms[a]
    66. # 绘制圆角矩形
    67. draw = ImageDraw.Draw(image)
    68. # 绘制圆角矩形
    69. for i, position in enumerate(rect_positions):
    70. x, y = position
    71. draw.rounded_rectangle([x, y, x + rect_width, y + rect_height], radius, fill=colors[i], outline='black', width=1)
    72. # 设置字体路径和大小
    73. font_path = r'C:\Windows\Fonts\AdobeHeitiStd-Regular.otf'
    74. font_size = 40
    75. # 加载字体
    76. font = ImageFont.truetype(font_path, font_size)
    77. # 在指定位置绘制文字
    78. draw.text((200, 30), f'彩色鱼骨图({name}CM)-{a+1:03d}', font=font, fill='black')
    79. # 保存图片
    80. image.save(new_path + fr'\{a+1:0{num_digits}d}.png')
    81. print('-----2、制作大图--------')
    82. # 六色所有排序方式 720种
    83. # 使用itertools.permutations生成所有不重复排序方式
    84. from PIL import Image, ImageDraw
    85. import itertools
    86. path = r'C:\Users\jg2yXRZ\OneDrive\桌面\鱼骨图'
    87. new_path_jpg = path + r'\02jpg(6.5乘1)'
    88. os.makedirs(new_path_jpg, exist_ok=True)
    89. name = '6.5乘1'
    90. for b in range(2):
    91. image = Image.open(path + r'\鱼骨图.jpg')
    92. long = 844
    93. wide = 378
    94. s = 6
    95. canvas = Image.new('RGB', (long, wide), 'white')
    96. draw = ImageDraw.Draw(canvas)
    97. radius = 20
    98. left = 220
    99. right = 180
    100. padding = 30
    101. rect_width = float((long - left - right - padding * 7) / 6)
    102. print(rect_width)
    103. rect_height = float(rect_width * 6.5)
    104. padding2 = float((wide - rect_height - 20))
    105. rect_positions = [
    106. (padding + left, padding2),
    107. (rect_width + padding * 2 + left, padding2),
    108. (rect_width * 2 + padding * 3 + left, padding2),
    109. (rect_width * 3 + padding * 4 + left, padding2),
    110. (rect_width * 4 + padding * 5 + left, padding2),
    111. (rect_width * 5 + padding * 6 + left, padding2)
    112. ]
    113. colors = perms[a]
    114. draw = ImageDraw.Draw(image)
    115. # 绘制圆角矩形
    116. for i, position in enumerate(rect_positions):
    117. x, y = position
    118. draw.rounded_rectangle([x, y, x + rect_width, y + rect_height], radius, fill='white', outline='black', width=1)
    119. # 设置字体路径和大小
    120. font_path = r'C:\Windows\Fonts\AdobeHeitiStd-Regular.otf'
    121. font_size = 40
    122. # 加载字体
    123. font = ImageFont.truetype(font_path, font_size)
    124. # 在指定位置绘制文字
    125. draw.text((150, 30), f'彩色鱼骨图({name}CM)-操作图{b+1}', font=font, fill='black')
    126. # 保存图片
    127. # image.save(new_path + fr'\{a+1:0{num_digits}d}.png')
    128. image.save(new_path_jpg + fr'\鱼骨图{name}_大图{b+1}.png')
    129. print('-----3、图卡制作成图片格式----------')
    130. import os
    131. import random
    132. from docx import Document
    133. from docx.shared import Cm
    134. from docx2pdf import convert
    135. from PyPDF2 import PdfFileMerger
    136. new_folder = path + r'\零时文件夹'
    137. os.makedirs(new_folder, exist_ok=True)
    138. image_files = [os.path.join(new_path, file) for file in os.listdir(new_path) if file.endswith('.png')]
    139. # random.shuffle(image_files)
    140. grouped_files = [image_files[i:i + 6] for i in range(0, len(image_files), 6)]
    141. for group_index, group in enumerate(grouped_files):
    142. doc = Document(path + r'\鱼骨图题卡.docx')
    143. table = doc.tables[0]
    144. for cell_index, image_file in enumerate(group):
    145. cell = table.cell(int(cell_index / 2), cell_index % 2)
    146. cell_paragraph = cell.paragraphs[0]
    147. cell_paragraph.clear()
    148. run = cell_paragraph.add_run()
    149. run.add_picture(image_file, width=Cm(13.92), height=Cm(6.49))
    150. doc.save(os.path.join(new_folder, f'{group_index + 1:03d}.docx'))
    151. # pdf_output_path = path + fr'\\鱼骨图({name})题卡{len(perms)}张_固定顺序.pdf'
    152. pdf_output_path = path + fr'\\鱼骨图({name})题卡{len(perms)}张_随机顺序.pdf'
    153. for docx_file in os.listdir(new_folder):
    154. if docx_file.endswith('.docx'):
    155. docx_path = os.path.join(new_folder, docx_file)
    156. convert(docx_path, docx_path.replace('.docx', '.pdf'))
    157. merger = PdfFileMerger()
    158. for pdf_file in os.listdir(new_folder):
    159. if pdf_file.endswith('.pdf'):
    160. pdf_path = os.path.join(new_folder, pdf_file)
    161. merger.append(pdf_path)
    162. merger.write(pdf_output_path)
    163. merger.close()
    164. import shutil
    165. shutil.rmtree(new_folder)
    166. print('-----4、图卡制作成操作图格式----------')
    167. import os
    168. import random
    169. from docx import Document
    170. from docx.shared import Cm
    171. from docx2pdf import convert
    172. from PyPDF2 import PdfFileMerger
    173. new_folder = path + r'\零时文件夹'
    174. os.makedirs(new_folder, exist_ok=True)
    175. image_files = [os.path.join(new_path_jpg, file) for file in os.listdir(new_path_jpg) if file.endswith('.png')]
    176. # random.shuffle(image_files)
    177. grouped_files = [image_files[i:i + 2] for i in range(0, len(image_files), 2)]
    178. for group_index, group in enumerate(grouped_files):
    179. doc = Document(path + r'\鱼骨图操作图.docx')
    180. table = doc.tables[0]
    181. for cell_index, image_file in enumerate(group):
    182. cell = table.cell(int(cell_index / 1), cell_index % 1)
    183. cell_paragraph = cell.paragraphs[0]
    184. cell_paragraph.clear()
    185. run = cell_paragraph.add_run()
    186. run.add_picture(image_file, width=Cm(21.62), height=Cm(9.7))
    187. doc.save(os.path.join(new_folder, f'{group_index + 1:03d}.docx'))
    188. # pdf_output_path = path + fr'\\鱼骨图({name})操作卡2张_固定顺序.pdf'
    189. pdf_output_path = path + fr'\\鱼骨图({name})操作卡2张_随机顺序.pdf'
    190. for docx_file in os.listdir(new_folder):
    191. if docx_file.endswith('.docx'):
    192. docx_path = os.path.join(new_folder, docx_file)
    193. convert(docx_path, docx_path.replace('.docx', '.pdf'))
    194. merger = PdfFileMerger()
    195. for pdf_file in os.listdir(new_folder):
    196. if pdf_file.endswith('.pdf'):
    197. pdf_path = os.path.join(new_folder, pdf_file)
    198. merger.append(pdf_path)
    199. merger.write(pdf_output_path)
    200. merger.close()
    201. import shutil
    202. shutil.rmtree(new_folder)

    以上就是6.5*1冰棍棒的教具,不过我还要把操作图打印出来看看,空白的棒子是不是正好6.5*1CM,与实体棒子一样长短大小。

  • 相关阅读:
    latex里的box
    在 MIT 教了大半辈子书,他学会 10 件事
    SQL注入靶机练习:BUU SQL COURSE 1
    elementui <el-autocomplete> querySearchAsync 搜索手机号码,补全信息
    【C语言】模拟实现字符串库函数
    华为机试真题 Java 实现【报文解压缩】
    Office 2021 小型企业版商用办公软件评测:提升工作效率与协作能力的专业利器
    【黄啊码】用PHP7性能居然是5.6的三倍?赶紧看看它有什么新特性
    cocos入门7:cocos creator 中的ui系统
    【无标题】
  • 原文地址:https://blog.csdn.net/reasonsummer/article/details/139813897