Separate Studio 2 source and canvas and apply size and seed choices

This commit is contained in:
Towsty
2026-09-11 07:07:26 -05:00
parent 09c96c0ae7
commit bf58732690
11 changed files with 163 additions and 41 deletions
+17
View File
@@ -0,0 +1,17 @@
let previous
export function randomSeed() {
const bytes = new Uint32Array(1)
globalThis.crypto.getRandomValues(bytes)
let seed = 2 + bytes[0] % 2147483646
if (seed === previous) seed = seed === 2147483647 ? 2 : seed + 1
previous = seed
return seed
}
export function queueSeeds(settings = {}, count = 1) {
if (settings.seedMode === 'locked') {
const seed=Number(settings.seed)
if (!Number.isInteger(seed) || seed<0 || seed>2147483647) throw Object.assign(new Error('Invalid seed.'),{statusCode:400})
return Array(count).fill(seed)
}
return Array.from({length:count},()=>randomSeed())
}