// The seed arithmetic under every piece of paper — hashing, not look.//// Moved out of `Paper/` so the paper's files carry only the theme's numbers:// what is here picks WHICH ring a sheet reads (a salt, a multiplier, the// xorshift stream), never how deep, how busy or how big anything is drawn.// Changing any of it re-deals every sheet's edge, so it is fixed in code and// never a theme knob.importFoundation/// The xorshift stream `PaperNoise` reads, and the mixing that starts it.publicenumSeededNoise {/// The golden-ratio multiplier that spreads a salt across the state, and/// the state a zero would otherwise collapse to.staticlet spread: UInt64 = 0x9E37_79B9_7F4A_7C15/// How finely one step of the stream is cut into 0…1.staticlet resolution: UInt64 = 100_000/// The fewest control points a ring can interpolate between.staticlet minimumRing = 2/// Steps one index (a side, a corner) into its own salt.publicstaticlet lane: UInt64 = 0x0001_0001/// The stream's first state for a seed's hash and a salt.staticfunc start(_ hash: UInt64, salt: UInt64) -> UInt64 {var state = hash ^ (salt &* spread)if state == 0 { state = spread }return state }/// Advances the stream one step and reads it, in 0…1.staticfunc advance(_ state: inout UInt64) -> Double { state ^= state << 13 state ^= state >> 7 state ^= state << 17returnDouble(state % resolution) / Double(resolution) }/// Raised cosine: flat where two control points meet, so an edge has no/// visible kinks.staticfunc eased(_ fraction: Double) -> Double { (1 - cos(fraction * Double.pi)) / 2 }}/// The salts — one per thing that reads noise, so two uses of one seed never/// read the same ring. Each spells its use in ASCII.publicenumPaperSalt {// PaperShapepublicstaticlet wave: UInt64 = 0x7761_7665// "wave"publicstaticlet corner: UInt64 = 0x636f_726e// "corn"publicstaticlet cornerLeaving: UInt64 = 0x55publicstaticlet longWave: UInt64 = 0x11publicstaticlet ripple: UInt64 = 0x22publicstaticlet nicks: UInt64 = 0x33publicstaticlet envelope: UInt64 = 0x44// PaperPhotopublicstaticlet flip: UInt64 = 0x666c_6970// "flip"publicstaticlet flipVertical: UInt64 = 0x5f// Markspublicstaticlet rule: UInt64 = 0x7275_6c65// "rule"publicstaticlet underline: UInt64 = 0x756e_6472// "undr"publicstaticlet circle: UInt64 = 0x6369_7263// "circ"publicstaticlet star: UInt64 = 0x7374_6172// "star"publicstaticlet progress: UInt64 = 0x7072_6772// "prgr"}/// The cached sheet pictures' budget — memory bookkeeping, not look: a sheet/// over it is drawn in layers, which draw the same pixels.publicenumPaperSurfaceImageBudget {/// The most pixels one cached picture may hold.publicstaticlet maxPixels: CGFloat = 4_194_304publicstaticlet countLimit = 256publicstaticlet costLimit = 32 * 1024 * 1024}