feat(editor): add --gen-texture-swirl logarithmic-spiral

70th procedural texture: N-arm logarithmic spiral. Each
pixel computes its polar angle minus log(r)*spiralFactor
and tests whether that "spiral phase" falls inside any
arm's angular band (mod 2π/N).

Distinct from --gen-texture-starburst (straight rays from
center) — this is the curved-arm vortex variant. Small
spiralFactor gives loose pinwheel arms; large factor gives
tight whirlpool spirals.

Useful for magic sigils, summoning circles, ritual floor
markings, mystical-pool surfaces, mage-tower mosaic floors,
shaman-totem ground inlays. Center-based pattern (doesn't
tile seamlessly), so best used as standalone decals rather
than wall textures.
This commit is contained in:
Kelsi 2026-05-09 13:08:07 -07:00
parent bdeb93bedd
commit 8d75dd3867
3 changed files with 69 additions and 1 deletions

View file

@ -105,7 +105,7 @@ const char* const kArgRequired[] = {
"--gen-texture-blueprint", "--gen-texture-rust-streaks",
"--gen-texture-plaid", "--gen-texture-diamond-grid",
"--gen-texture-houndstooth", "--gen-texture-chevron",
"--gen-texture-dunes",
"--gen-texture-dunes", "--gen-texture-swirl",
"--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes",
"--validate-jsondbc", "--check-glb-bounds", "--validate-stl",
"--validate-png", "--validate-blp",

View file

@ -3500,6 +3500,71 @@ int handleKnit(int& i, int argc, char** argv) {
return 0;
}
int handleSwirl(int& i, int argc, char** argv) {
// Logarithmic spiral: pixels are colored as the spiral arm
// when (θ - log(r) * spiralFactor) mod 2π/N falls inside a
// small angular band. N independent arms tile the circle.
// Distinct from --gen-texture-starburst (straight rays from
// center) — this is the curved-arm vortex variant for magic
// sigils, summoning circles, ritual floor markings, mystical-
// pool surfaces.
std::string outPath = argv[++i];
std::string bgHex = argv[++i];
std::string armHex = argv[++i];
int armCount = 3;
float spiralFactor = 0.4f; // higher = tighter spiral
float armWidth = 0.30f; // radians half-width
int W = 256, H = 256;
parseOptInt(i, argc, argv, armCount);
parseOptFloat(i, argc, argv, spiralFactor);
parseOptFloat(i, argc, argv, armWidth);
parseOptInt(i, argc, argv, W);
parseOptInt(i, argc, argv, H);
if (W < 1 || H < 1 || W > 8192 || H > 8192 ||
armCount < 1 || armCount > 32 ||
spiralFactor <= 0.0f || spiralFactor > 10.0f ||
armWidth <= 0.0f || armWidth >= 3.14f) {
std::fprintf(stderr,
"gen-texture-swirl: invalid dims (W/H 1..8192, "
"armCount 1..32, spiralFactor (0,10], armWidth (0,π))\n");
return 1;
}
uint8_t br_, bg_, bb_, ar, ag, ab;
if (!parseHexOrError(bgHex, br_, bg_, bb_, "gen-texture-swirl")) return 1;
if (!parseHexOrError(armHex, ar, ag, ab,
"gen-texture-swirl")) return 1;
std::vector<uint8_t> pixels(static_cast<size_t>(W) * H * 3, 0);
const float twoPi = 6.28318530717958f;
const float cx = W * 0.5f;
const float cy = H * 0.5f;
const float anglePer = twoPi / armCount;
for (int y = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
float dx = x - cx;
float dy = y - cy;
float r = std::sqrt(dx * dx + dy * dy);
// Avoid log(0) at the center: use r+1.
float armPhase = std::atan2(dy, dx) -
std::log(r + 1.0f) * spiralFactor;
float wrapped = std::fmod(armPhase + 100.0f * twoPi, anglePer);
float angDist = std::min(wrapped, anglePer - wrapped);
uint8_t outR, outG, outB;
if (angDist < armWidth) {
outR = ar; outG = ag; outB = ab;
} else {
outR = br_; outG = bg_; outB = bb_;
}
setPixelRGB(pixels, W, x, y, outR, outG, outB);
}
}
if (!savePngOrError(outPath, W, H, pixels, "gen-texture-swirl")) return 1;
printPngWrote(outPath, W, H);
std::printf(" bg/arm : %s / %s\n", bgHex.c_str(), armHex.c_str());
std::printf(" spiral : %d arms, factor=%.2f, width=%.3f rad\n",
armCount, spiralFactor, armWidth);
return 0;
}
int handleDunes(int& i, int argc, char** argv) {
// Sand dunes / wave-ripple pattern: a stack of parallel
// sinusoidal curves spaced verticalSpacing apart. A pixel
@ -5079,6 +5144,7 @@ constexpr TextureEntry kTextureTable[] = {
{"--gen-texture-houndstooth", 3, handleHoundstooth},
{"--gen-texture-chevron", 3, handleChevron},
{"--gen-texture-dunes", 3, handleDunes},
{"--gen-texture-swirl", 3, handleSwirl},
};
} // namespace

View file

@ -173,6 +173,8 @@ void printUsage(const char* argv0) {
std::printf(" Chevron: stack of V-shape stripes with sharp seams (military / sportswear / heraldic banners)\n");
std::printf(" --gen-texture-dunes <out.png> <bgHex> <lineHex> [verticalSpacing] [period] [amp] [lineW] [W H]\n");
std::printf(" Dunes: stack of parallel sinusoidal curves (desert ground / shallow-water sand / wave ripples)\n");
std::printf(" --gen-texture-swirl <out.png> <bgHex> <armHex> [armCount] [spiralFactor] [armWidth] [W H]\n");
std::printf(" Swirl: N-arm logarithmic spiral (magic sigils / summoning circles / ritual floor markings)\n");
std::printf(" --add-texture-to-zone <zoneDir> <png-path> [renameTo]\n");
std::printf(" Copy an existing PNG into <zoneDir> (optionally renaming it on the way in)\n");
std::printf(" --gen-mesh <wom-base> <cube|plane|sphere|cylinder|torus|cone|ramp> [size]\n");