feat:2.6.1增加 数物对应 和 根据颜色画图形
This commit is contained in:
@@ -127,6 +127,28 @@ export function getRandomNumberColor(): string {
|
||||
return colors[Math.floor(Math.random() * colors.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 NUMBER_COLORS 中随机获取指定数量的不重复颜色
|
||||
* @param count 需要获取的颜色数量
|
||||
* @returns 不重复的颜色数组
|
||||
*/
|
||||
export function getRandomUniqueNumberColors(count: number): string[] {
|
||||
const allColors = getNumberColors();
|
||||
if (count >= allColors.length) {
|
||||
// 如果需要的数量大于等于总数,返回打乱后的所有颜色
|
||||
return [...allColors].sort(() => Math.random() - 0.5);
|
||||
}
|
||||
|
||||
// 使用 Set 确保不重复
|
||||
const selectedColors = new Set<string>();
|
||||
while (selectedColors.size < count) {
|
||||
const randomIndex = Math.floor(Math.random() * allColors.length);
|
||||
selectedColors.add(allColors[randomIndex]);
|
||||
}
|
||||
|
||||
return Array.from(selectedColors);
|
||||
}
|
||||
|
||||
export const PAPER_SIZE = {
|
||||
A4: {
|
||||
// width: 2480,
|
||||
|
||||
Reference in New Issue
Block a user