export type WaterbodyVisual = { shore: number; waves: number; markerX: number; markerY: number; code: string; }; export function stableVisualHash(identity: string): number { return [...identity.trim().toLocaleLowerCase("ru")] .reduce((hash, char) => Math.imul(hash ^ (char.codePointAt(0) ?? 0), 16777619) >>> 0, 2166136261); } export function waterbodyVisual(identity: string): WaterbodyVisual { const hash = stableVisualHash(identity || "waterbody"); return { shore: hash % 8, waves: 1 + ((hash >>> 4) % 3), markerX: 32 + ((hash >>> 8) % 59), markerY: 18 + ((hash >>> 15) % 23), code: hash.toString(36).toUpperCase().padStart(2, "0").slice(-2), }; }