【教学类-43-25】20240311 数独3宫格的所有可能(图片版 12套样式,空1格-空8格,每套510张,共6120小图)
背景需求:
有一位客户买3宫格所有可能(WORD表格版)
【教学类-43-25】20241203 数独3宫格的所有可能-使用模版替换-用时少报错少(12套样式,空1格-空8格,每套510张,共6120小图)_数独三宫格题目-CSDN博客文章浏览阅读2.3k次,点赞74次,收藏9次。【教学类-43-25】20241203 数独3宫格的所有可能-使用模版替换-用时少报错少(12套样式,空1格-空8格,每套510张,共6120小图)_数独三宫格题目https://blog.csdn.net/reasonsummer/article/details/144225973?spm=1011.2415.3001.5331
这让我想起3宫格生成的漫长时间(510图*12套生成了8个小时),还有4宫格生成的恐惧——用word的12图插入数字的方法,页数太多,合并WORD总是卡死,无法合并成一个文件
修改思路
所以这次参考“像素图(图片版)”,也做一份所有数独样式的图片版
【教学类-13-19】20250228《数字色块像素图》图片版(1-4位数)-CSDN博客文章浏览阅读1.5k次,点赞48次,收藏13次。【教学类-13-19】20250228《数字色块像素图》图片版(1-4位数)https://blog.csdn.net/reasonsummer/article/details/145931618?spm=1011.2415.3001.5331
测试过程不提,直接上代码
'''
目的:数独3宫格,所有可能样式,做成图片
作者:阿夏
时间:20250311
'''
import math,os,time
from itertools import permutations
import random
from win32com.client import constants, gencache
from win32com.client.gencache import EnsureDispatch
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_BREAK
from docx.oxml.ns import qn
from docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
import os
import copy
# 开始时间
start_time = datetime.now()
# 制作"单元格"# 几宫格
hs=3
# int(input('3宫格数独=3\n'))
# 内容太多了,容易报错,如果报错,就重新设置起始宫格数字1-8
start=1
# 第几套,第一套
# 新建一个”装N份word和PDF“的临时文件夹
# 创建输出目录
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\20250311 3宫格所有可能(图片版)\01三宫格图片版'
output_dir = path + r'\00全部'
os.makedirs(output_dir, exist_ok=True)
print('------第2步:制作3宫格的12套题的内容-------')
# 制作3宫格的12套题目(没有空格,只有基础模板)
lst=[]
for b in range(1,hs+1):
lst.append(b)
print(lst)
permutations_list = list(permutations(lst))
numbers = [list(permutation) for permutation in permutations_list]
print(numbers)
# [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
# 6种组合
# 互相组合成3组
import itertools
# 计算排列数量并生成所有可能的排列
combinations2 = list(itertools.permutations(numbers, hs))
# 包含相似的
# 输出排列数量
print(len(combinations2))
# 120
# # 把所有数字都提取成元素
ll=[]
for o1 in combinations2:
for o2 in o1:
for o3 in o2:
ll.append(o3)
print(ll)
print(len(ll))
# 1080
v=hs*hs
# 9个数字抽取一组
f=[]
for i in range(int(len(ll)/v)):
f.append(ll[i*v:i*v+v])
# print(f)
# print(len(f))
#120条
# # # 遍历表格,把0、5、10相同的内容删除,横向的数字1234都正确了,现在只要排除竖向不对的
P=[]
z=[]
for k in f:
if int(k[0])!=int(k[3])!=int(k[6]) and int(k[0])+int(k[3])+int(k[6])==6 and\
int(k[1])!=int(k[4])!=int(k[7]) and int(k[1])+int(k[4])+int(k[7])==6 and\
int(k[2])!=int(k[5])!=int(k[8]) and int(k[2])+int(k[5])+int(k[8])==6 and\
int(k[0])!=int(k[1])!=int(k[2]) and int(k[0])+int(k[1])+int(k[2])==6 and\
int(k[3])!=int(k[4])!=int(k[5]) and int(k[3])+int(k[4])+int(k[5])==6 and\
int(k[6])!=int(k[7])!=int(k[8]) and int(k[6])+int(k[7])+int(k[8])==6 :
z.append(k)
print(z)
print(len(z))
# 12种基础样式
basis=[]
for hh in z:
print(hh)
basis.append(hh)
print(basis)
print(len(basis)) # 12种基础样式
# [1, 2, 3, 2, 3, 1, 3, 1, 2]
# [1, 2, 3, 3, 1, 2, 2, 3, 1]
# [1, 3, 2, 2, 1, 3, 3, 2, 1]
# [1, 3, 2, 3, 2, 1, 2, 1, 3]
# [2, 1, 3, 1, 3, 2, 3, 2, 1]
# [2, 1, 3, 3, 2, 1, 1, 3, 2]
# [2, 3, 1, 1, 2, 3, 3, 1, 2]
# [2, 3, 1, 3, 1, 2, 1, 2, 3]
# [3, 1, 2, 1, 2, 3, 2, 3, 1]
# [3, 1, 2, 2, 3, 1, 1, 2, 3]
# [3, 2, 1, 1, 3, 2, 2, 1, 3]
# [3, 2, 1, 2, 1, 3, 1, 3, 2]
# # # 12道题目
jc=path+fr'\{hs}宫格 基础{int(len(basis))}种'
os.makedirs(jc,exist_ok=True)
# 制作12张原始基础样式
for n2 in range(len(basis)):
# for ns in range(len(styles2[nt][nr])):
t2=basis[n2]
print(t2)
# 设置画布参数
rows = 3
cols = 3
cell_size = 100
border_width = 10
canvas_width = cols * cell_size + border_width * 2
canvas_height = rows * cell_size + border_width * 2
# 加载字体
font_path = r'C:\Windows\Fonts\arial.ttf' # 替换成你的字体文件路径
font_size = 60
font = ImageFont.truetype(font_path, font_size)
# 创建图像
canvas_color = (255, 255, 255) # 白色
image = Image.new('RGB', (canvas_width, canvas_height), canvas_color)
draw = ImageDraw.Draw(image)
# 绘制边框
draw.rectangle([(0, 0), (canvas_width, canvas_height)], outline=(0, 0, 0), width=border_width)
# 计算内部区域的起始点和结束点
inner_start_x = border_width
inner_end_x = canvas_width - border_width
inner_start_y = border_width
inner_end_y = canvas_height - border_width
# 绘制表格(去掉边框线10磅)
for row in range(rows + 1):
start_y = inner_start_y + row * cell_size
draw.line((inner_start_x, start_y, inner_end_x, start_y), fill=(0, 0, 0)) # 水平线
for col in range(cols + 1):
start_x = inner_start_x + col * cell_size
draw.line((start_x, inner_start_y, start_x, inner_end_y), fill=(0, 0, 0)) # 垂直线
# 在每个单元格的中心点写入数字
for row in range(rows):
for col in range(cols):
index = row * cols + col
number = t2[index]
text = str(number)
text_width, text_height = draw.textsize(text, font=font)
center_x = inner_start_x + col * cell_size + (cell_size - text_width) // 2
center_y = inner_start_y + row * cell_size + (cell_size - text_height) // 2 - 10
# 绘制数字
draw.text((center_x, center_y), text, font=font, fill=(0, 0, 0))
# 绘制下划线
underline_y = center_y + text_height // 1 + 10 # 调整下划线位置,使其位于数字下方
draw.line((center_x - text_width //10, underline_y, center_x + text_width *1, underline_y), fill=(0, 0, 0), width=2)
# 保存图像
output_path1 = os.path.join(jc, f'{hs}宫格 基础样式{n2+1:02}.png')
image.save(output_path1)
print(f"Image saved to {output_path1}")
print('---------第3步,原始列表生成样式1,了解数量和空格位置----------')
# 读取每一款,假设任意缺1空、任意缺2空,任意缺三空
# 原始列表
import itertools
m=1
names=[]
styles1=[]
styles2=[]
for a1 in range(len(basis)):
a=basis[a1]
print(a)
# [1, 2, 3, 2, 3, 1, 3, 1, 2]
# 12张一页的样式
n=0
xx=0
for x in range(start,hs*hs):
# 如果报错,就从相应的宫格数字继续生成
l1=[]
# 使用 combinations 生成所有不重复的组合
combinations = list(itertools.combinations(range(len(a)), x))
# 1有9次,2有36次,,3有84次,4有84次,3有84次,3有84次,3有84次,3有84次,3有84次,3有84次
# 打印组合及其索引,并将索引位置的内容变成 ''
for comb in combinations:
# 创建副本以避免修改原始列表
modified_list = a[:]
# 将组合中的索引位置内容替换为 ''
for index in comb:
modified_list[index] = ''
# print(f"{modified_list}")
# print(f"Combination: {[modified_list[i] for i in comb]}, Indices: {comb}")
l1.append(modified_list)
# 输出组合的数量
# print(l)
t=f"{hs}宫格 样式{a1+1:02} {x}空有{len(l1)}种"
print(f"{hs}宫格 样式{a1+1:02} {x}空有{len(l1)}种")
names.append(t)
# 1空有9种
# 2空有36种
# 3空有84种
# 4空有126种
# 5空有126种
# 6空有84种
# 7空有36种
# 8空有9种
# 9空有1种
n+=len(combinations)
# # 3宫格1套,511种,
# print(n)
# 510
# # 3宫格1套,12种图案,每种510,共6132种,
# print(n*len(basis))
# print(n*576)
# 将嵌套列表转换为扁平列表
flat_list = [item for sublist in l1 for item in sublist]
print(flat_list)
print(len(flat_list))
# 81
# 将 flat_list 拆分成每组包含9个元素的嵌套列表
grouped_list= [flat_list[i:i + hs*hs] for i in range(0, len(flat_list), hs*hs)]
print(grouped_list)
print(len(grouped_list))
print('数字9个',grouped_list)
styles1.append(grouped_list)
# styles2.append(styles1)
print(names)
print(len(names))
# 8种名称1-9
# 96种
# print(styles1)
# print(len(styles1))
# print(styles2)
# print(len(styles2))
# 96种
# # 8种列表,每种数量不等,呈现正态分布
for nt in range(len(styles1)):
# 按照样式1、2、3分组
# wj=output_dir+fr'\{hs}宫格 样式{nt:02}'
# os.makedirs(wj,exist_ok=True)
for nr in range(len(styles1[nt])):
# for ns in range(len(styles2[nt][nr])):
t=styles1[nt][nr]
print(t)
# 设置画布参数
rows = 3
cols = 3
cell_size = 100
border_width = 10
canvas_width = cols * cell_size + border_width * 2
canvas_height = rows * cell_size + border_width * 2
# 加载字体
font_path = r'C:\Windows\Fonts\arial.ttf' # 替换成你的字体文件路径
font_size = 60
font = ImageFont.truetype(font_path, font_size)
# 创建图像
canvas_color = (255, 255, 255) # 白色
image = Image.new('RGB', (canvas_width, canvas_height), canvas_color)
draw = ImageDraw.Draw(image)
# 绘制边框
draw.rectangle([(0, 0), (canvas_width, canvas_height)], outline=(0, 0, 0), width=border_width)
# 计算内部区域的起始点和结束点
inner_start_x = border_width
inner_end_x = canvas_width - border_width
inner_start_y = border_width
inner_end_y = canvas_height - border_width
# 绘制表格(去掉边框线10磅)
for row in range(rows + 1):
start_y = inner_start_y + row * cell_size
draw.line((inner_start_x, start_y, inner_end_x, start_y), fill=(0, 0, 0)) # 水平线
for col in range(cols + 1):
start_x = inner_start_x + col * cell_size
draw.line((start_x, inner_start_y, start_x, inner_end_y), fill=(0, 0, 0)) # 垂直线
# 在每个单元格的中心点写入数字
for row in range(rows):
for col in range(cols):
index = row * cols + col
number = t[index]
text = str(number)
text_width, text_height = draw.textsize(text, font=font)
center_x = inner_start_x + col * cell_size + (cell_size - text_width) // 2
center_y = inner_start_y + row * cell_size + (cell_size - text_height) // 2 - 10
# 绘制数字
draw.text((center_x, center_y), text, font=font, fill=(0, 0, 0))
# 绘制下划线
underline_y = center_y + text_height // 1 + 10 # 调整下划线位置,使其位于数字下方
draw.line((center_x - text_width //10, underline_y, center_x + text_width *1, underline_y), fill=(0, 0, 0), width=2)
# 保存图像
output_path = os.path.join(output_dir, f'{names[nt]} {nr+1:03}.png')
image.save(output_path)
print(f"Image saved to {output_path}")
# 每510张打包再一起,样式1 510张、样式2 510张、样式3 510张
import os
import shutil
# 设置源文件夹路径
source_folder = output_dir
print(source_folder)
# C:\Users\jg2yXRZ\OneDrive\桌面\20250311 3宫格所有可能(图片版)\01三宫格图片版\00全部
basis = ['1'] * 12
n = 510
hs = 3 # Assuming hs is defined somewhere in your code
# path = "your_path" # Replace with your actual path
# 创建目标文件夹
for i in range(1, int(len(basis) + 1)): # 假设总共有30个文件,分成3组
folder_name = os.path.join(path, f"{hs}宫格 样式{i:02}")
os.makedirs(folder_name, exist_ok=True)
# 获取所有图片文件名
image_files = [f for f in os.listdir(source_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
# 分组并复制文件 n=510
group_size = n
for i, file in enumerate(image_files):
group_index = i // group_size + 1 # 计算当前文件属于第几组
source_path = os.path.join(source_folder, file)
destination_path = os.path.join(path, f"{hs}宫格 样式{group_index:02}", file)
shutil.copy(source_path, destination_path)
print(f"Copied {file} to {destination_path}")
# 记录程序结束时间
end_time = datetime.now()
# 计算程序运行时间
elapsed_time = end_time - start_time
print(f"数独{hs}宫格程序开始时间:{start_time}")
print(f"数独{hs}宫格程序结束时间:{end_time}")
# 打印程序运行时间
print("程序运行时间:", elapsed_time)
第1步:生成3宫格12套基本样式

第2步:生成3宫格每套基本样式中的所有可能(空1格有9种,空2个有36种……)每种有510种不同图案)乘以12套
第3步:以510张为分割,图片复制到“样式1”“样式2”文件夹中。
好了,用这个方法优势:
1、生成图片是320*320像素
2、大小都是9KB
3、6120张图片生成和转移时间大约2分钟。
以图片方式直接获取数独内容,可以反复引用,制作出一页12张,一页6张,一页2张,一页1张的模版。
做成PDF,可能生成WORD的时间比较长
后续
把这个代码修改一下,做 一套4宫格所有可能(图片版)
'''
目的:数独4宫格,所有可能样式,做成图片(调整下划线位置
作者:阿夏
时间:20250311
'''
import math,os,time
from itertools import permutations
import random
from win32com.client import constants, gencache
from win32com.client.gencache import EnsureDispatch
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_BREAK
from docx.oxml.ns import qn
from docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
import os
import copy
# 开始时间
start_time = datetime.now()
# 制作"单元格"# 几宫格
hs=4
# int(input('4宫格数独=3\n'))
# 内容太多了,容易报错,如果报错,就重新设置起始宫格数字1-8
start=1
# 第几套,第一套
# 新建一个”装N份word和PDF“的临时文件夹
# 创建输出目录
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\20250311 4宫格所有可能(图片版)\01四宫格图片版'
os.makedirs(path, exist_ok=True)
output_dir = path + r'\00全部'
os.makedirs(output_dir, exist_ok=True)
print('------第2步:制作4宫格的12套题的内容-------')
# 制作4宫格的12套题目(没有空格,只有基础模板)
lst=[]
for b in range(1,hs+1):
lst.append(b)
print(lst)
permutations_list = list(permutations(lst))
numbers = [list(permutation) for permutation in permutations_list]
# print(numbers)
# [[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]PS D:\test>
# 6种组合
# 互相组合成3组
import itertools
# 计算排列数量并生成所有可能的排列
combinations2 = list(itertools.permutations(numbers, hs))
# 包含相似的
# 输出排列数量
print(len(combinations2))
# 120
# # 把所有数字都提取成元素
ll=[]
for o1 in combinations2:
for o2 in o1:
for o3 in o2:
ll.append(o3)
print(ll)
print(len(ll))
# 1080
v=hs*hs
# 9个数字抽取一组
f=[]
for i in range(int(len(ll)/v)):
f.append(ll[i*v:i*v+v])
# print(f)
# print(len(f))
#120条
# # # 遍历表格,把0、5、10相同的内容删除,横向的数字1234都正确了,现在只要排除竖向不对的
P=[]
z=[]
for k in f:
if int(k[0])!=int(k[4])and int(k[0])!=int(k[8])and int(k[0])!=int(k[12]) and int(k[4])!=int(k[8]) and int(k[4])!=int(k[12])and int(k[8])!=int(k[12]) and int(k[0])+int(k[4])+int(k[8])+int(k[12])==10 and \
int(k[1])!=int(k[5])and int(k[1])!=int(k[9])and int(k[1])!=int(k[13]) and int(k[5])!=int(k[9]) and int(k[5])!=int(k[13])and int(k[9])!=int(k[13]) and int(k[1])+int(k[5])+int(k[9])+int(k[13])==10 and \
int(k[2])!=int(k[6])and int(k[2])!=int(k[10])and int(k[2])!=int(k[14]) and int(k[6])!=int(k[10]) and int(k[6])!=int(k[14])and int(k[10])!=int(k[14]) and int(k[2])+int(k[6])+int(k[10])+int(k[14])==10 and\
int(k[3])!=int(k[7])and int(k[3])!=int(k[11])and int(k[3])!=int(k[15]) and int(k[7])!=int(k[11]) and int(k[7])!=int(k[15])and int(k[11])!=int(k[15]) and int(k[3])+int(k[7])+int(k[11])+int(k[15])==10:
z.append(k)
# print(z)
# print(len(z))
# 12种基础样式
basis=[]
for hh in z:
print(hh)
basis.append(hh)
# print(basis)
# print(len(basis)) # 576种基础样式
# [1, 2, 3, 4, 2, 1, 4, 3, 3, 4, 1, 2, 4, 3, 2, 1]
# [1, 2, 3, 4, 2, 1, 4, 3, 3, 4, 2, 1, 4, 3, 1, 2]
# [1, 2, 3, 4, 2, 1, 4, 3, 4, 3, 1, 2, 3, 4, 2, 1]
# [1, 2, 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(basis))}种'
os.makedirs(jc,exist_ok=True)
# 制作12张原始基础样式
for n2 in range(len(basis)):
# for ns in range(len(styles2[nt][nr])):
t2=basis[n2]
print(t2)
# 设置画布参数
rows = 4
cols = 4
cell_size = 100
border_width = 10
canvas_width = cols * cell_size + border_width * 2
canvas_height = rows * cell_size + border_width * 2
# 加载字体
font_path = r'C:\Windows\Fonts\arial.ttf' # 替换成你的字体文件路径
font_size = 60
font = ImageFont.truetype(font_path, font_size)
# 创建图像
canvas_color = (255, 255, 255) # 白色
image = Image.new('RGB', (canvas_width, canvas_height), canvas_color)
draw = ImageDraw.Draw(image)
# 绘制边框
draw.rectangle([(0, 0), (canvas_width, canvas_height)], outline=(0, 0, 0), width=border_width)
# 计算内部区域的起始点和结束点
inner_start_x = border_width
inner_end_x = canvas_width - border_width
inner_start_y = border_width
inner_end_y = canvas_height - border_width
# 绘制表格(去掉边框线10磅)
for row in range(rows + 1):
start_y = inner_start_y + row * cell_size
draw.line((inner_start_x, start_y, inner_end_x, start_y), fill=(0, 0, 0)) # 水平线
for col in range(cols + 1):
start_x = inner_start_x + col * cell_size
draw.line((start_x, inner_start_y, start_x, inner_end_y), fill=(0, 0, 0)) # 垂直线
# 在每个单元格的中心点写入数字
for row in range(rows):
for col in range(cols):
index = row * cols + col
number = t2[index]
text = str(number)
text_width, text_height = draw.textsize(text, font=font)
center_x = inner_start_x + col * cell_size + (cell_size - text_width) // 2
center_y = inner_start_y + row * cell_size + (cell_size - text_height) // 2 - 10
# 绘制数字
draw.text((center_x, center_y), text, font=font, fill=(0, 0, 0))
# 绘制下划线
underline_y = center_y + text_height // 1 + 10 # 调整下划线位置,使其位于数字下方
draw.line((center_x - text_width //10, underline_y, center_x + text_width *1, underline_y), fill=(0, 0, 0), width=2)
# 保存图像
output_path1 = os.path.join(jc, f'{hs}宫格 基础样式{n2+1:03}.png')
image.save(output_path1)
print(f"Image saved to {output_path1}")
print('---------第3步,原始列表生成样式1,了解数量和空格位置----------')
# 读取每一款,假设任意缺1空、任意缺2空,任意缺三空
# 原始列表
import itertools
m=1
names=[]
styles1=[]
styles2=[]
for a1 in range(len(basis)):
a=basis[a1]
print(a)
# [1, 2, 3, 2, 3, 1, 3, 1, 2]
# 12张一页的样式
n=0
xx=0
for x in range(start,hs*hs):
# 如果报错,就从相应的宫格数字继续生成
l1=[]
# 使用 combinations 生成所有不重复的组合
combinations = list(itertools.combinations(range(len(a)), x))
# 1有9次,2有36次,,3有84次,4有84次,3有84次,3有84次,3有84次,3有84次,3有84次,3有84次
# 打印组合及其索引,并将索引位置的内容变成 ''
for comb in combinations:
# 创建副本以避免修改原始列表
modified_list = a[:]
# 将组合中的索引位置内容替换为 ''
for index in comb:
modified_list[index] = ''
# print(f"{modified_list}")
# print(f"Combination: {[modified_list[i] for i in comb]}, Indices: {comb}")
l1.append(modified_list)
# 输出组合的数量
# print(l)
t=f"{hs}宫格 样式{a1+1:03} {x}空有{len(l1)}种"
print(f"{hs}宫格 样式{a1+1:03} {x}空有{len(l1)}种")
names.append(t)
# 1空有9种
# 2空有36种
# 3空有84种
# 4空有126种
# 5空有126种
# 6空有84种
# 7空有36种
# 8空有9种
# 9空有1种
n+=len(combinations)
# # 4宫格1套,511种,
# print(n)
# 510
# # 4宫格1套,12种图案,每种510,共6132种,
# print(n*len(basis))
# print(n*576)
# 将嵌套列表转换为扁平列表
flat_list = [item for sublist in l1 for item in sublist]
print(flat_list)
print(len(flat_list))
# 81
# 将 flat_list 拆分成每组包含9个元素的嵌套列表
grouped_list= [flat_list[i:i + hs*hs] for i in range(0, len(flat_list), hs*hs)]
print(grouped_list)
print(len(grouped_list))
print('数字9个',grouped_list)
styles1.append(grouped_list)
# styles2.append(styles1)
print(names)
print(len(names))
# 8种名称1-9
# 96种
# print(styles1)
# print(len(styles1))
# print(styles2)
# print(len(styles2))
# 96种
# # 8种列表,每种数量不等,呈现正态分布
for nt in range(len(styles1)):
# 按照样式1、2、3分组
# wj=output_dir+fr'\{hs}宫格 样式{nt:02}'
# os.makedirs(wj,exist_ok=True)
for nr in range(len(styles1[nt])):
# for ns in range(len(styles2[nt][nr])):
t=styles1[nt][nr]
print(t)
# 设置画布参数
rows = 4
cols = 4
cell_size = 100
border_width = 10
canvas_width = cols * cell_size + border_width * 2
canvas_height = rows * cell_size + border_width * 2
# 加载字体
font_path = r'C:\Windows\Fonts\arial.ttf' # 替换成你的字体文件路径
font_size = 60
font = ImageFont.truetype(font_path, font_size)
# 创建图像
canvas_color = (255, 255, 255) # 白色
image = Image.new('RGB', (canvas_width, canvas_height), canvas_color)
draw = ImageDraw.Draw(image)
# 绘制边框
draw.rectangle([(0, 0), (canvas_width, canvas_height)], outline=(0, 0, 0), width=border_width)
# 计算内部区域的起始点和结束点
inner_start_x = border_width
inner_end_x = canvas_width - border_width
inner_start_y = border_width
inner_end_y = canvas_height - border_width
# 绘制表格(去掉边框线10磅)
for row in range(rows + 1):
start_y = inner_start_y + row * cell_size
draw.line((inner_start_x, start_y, inner_end_x, start_y), fill=(0, 0, 0)) # 水平线
for col in range(cols + 1):
start_x = inner_start_x + col * cell_size
draw.line((start_x, inner_start_y, start_x, inner_end_y), fill=(0, 0, 0)) # 垂直线
# 在每个单元格的中心点写入数字
for row in range(rows):
for col in range(cols):
index = row * cols + col
number = t[index]
text = str(number)
text_width, text_height = draw.textsize(text, font=font)
center_x = inner_start_x + col * cell_size + (cell_size - text_width) // 2
center_y = inner_start_y + row * cell_size + (cell_size - text_height) // 2 - 10
# 绘制数字
draw.text((center_x, center_y), text, font=font, fill=(0, 0, 0))
# 绘制下划线
underline_y = center_y + text_height // 1 + 10 # 调整下划线位置,使其位于数字下方
draw.line((center_x - text_width //10, underline_y, center_x + text_width *1, underline_y), fill=(0, 0, 0), width=2)
# 保存图像
output_path = os.path.join(output_dir, f'{names[nt]} {nr+1:05}.png')
image.save(output_path)
print(f"Image saved to {output_path}")
# 每510张打包再一起,样式1 510张、样式2 510张、样式3 510张
import os
import shutil
# 设置源文件夹路径
source_folder = output_dir
print(source_folder)
# C:\Users\jg2yXRZ\OneDrive\桌面\20250311 4宫格所有可能(图片版)\01三宫格图片版\00全部
hs = 4 # Assuming hs is defined somewhere in your code
# path = "your_path" # Replace with your actual path
# 创建目标文件夹
for i in range(1, int(len(basis) + 1)): # 假设总共有30个文件,分成3组
folder_name = os.path.join(path, f"{hs}宫格 样式{i:03}")
os.makedirs(folder_name, exist_ok=True)
# 获取所有图片文件名
image_files = [f for f in os.listdir(source_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
# 分组并复制文件 n=510
group_size = n
for i, file in enumerate(image_files):
group_index = i // group_size + 1 # 计算当前文件属于第几组
source_path = os.path.join(source_folder, file)
destination_path = os.path.join(path, f"{hs}宫格 样式{group_index:05}", file)
shutil.copy(source_path, destination_path)
print(f"Copied {file} to {destination_path}")
# 记录程序结束时间
end_time = datetime.now()
# 计算程序运行时间
elapsed_time = end_time - start_time
print(f"数独{hs}宫格程序开始时间:{start_time}")
print(f"数独{hs}宫格程序结束时间:{end_time}")
# 打印程序运行时间
print("程序运行时间:", elapsed_time)