From 9eb37f01b7f34c750e2b3485575482e0a2270f82 Mon Sep 17 00:00:00 2001 From: yggdrasil75 Date: Thu, 13 Nov 2025 05:38:58 -0500 Subject: [PATCH] some more upgrades. not exactly what I expected, but its fun. --- tests/g2chromatic2.cpp | 49 ++++++++++++++++++++++++++------------- util/vectorlogic/vec4.hpp | 4 ++++ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/tests/g2chromatic2.cpp b/tests/g2chromatic2.cpp index d7580ef..5ed7c5e 100644 --- a/tests/g2chromatic2.cpp +++ b/tests/g2chromatic2.cpp @@ -11,8 +11,8 @@ #include "../util/timing_decorator.cpp" struct AnimationConfig { - int width = 128; - int height = 128; + int width = 256; + int height = 256; int totalFrames = 480; float fps = 30.0f; int numSeeds = 8; @@ -66,33 +66,53 @@ std::vector> pickSeeds(Grid2 grid, AnimationConfi return seeds; } -void expandPixel(Grid2& grid, AnimationConfig config, std::vector>& seeds, std::unordered_set& visited) { +void expandPixel(Grid2& grid, AnimationConfig config, std::vector>& seeds) { TIME_FUNCTION; std::vector> newseeds; + + + std::unordered_set visitedThisFrame; + for (const auto& seed : seeds) { + visitedThisFrame.insert(std::get<0>(seed)); + } + + for (const std::tuple& seed : seeds) { size_t id = std::get<0>(seed); Vec2 seedPOS = std::get<1>(seed); Vec4 seedColor = std::get<2>(seed); std::vector neighbors = grid.getNeighbors(id); for (size_t neighbor : neighbors) { - if (visited.find(neighbor) != visited.end()) { - continue; // Skip already processed neighbors + if (visitedThisFrame.count(neighbor)) { + continue; } - visited.insert(neighbor); + visitedThisFrame.insert(neighbor); + + Vec2 neipos = grid.getPositionID(neighbor); Vec4 neighborColor = grid.getColor(neighbor); float distance = seedPOS.distance(neipos); - float angle = seedPOS.angleTo(neipos); - Vec4 newcolor = Vec4(neighborColor.r * ((1.1f + angle) * std::sin(seedColor.r)), - neighborColor.g * ((1.1f + angle) * std::sin(seedColor.g)), - neighborColor.b * ((1.1f + angle) * std::sin(seedColor.b)), + float angle = seedPOS.directionTo(neipos); + + float normalizedAngle = (angle + M_PI) / (2.0f * M_PI); + float blendFactor = 0.3f + 0.4f * std::sin(normalizedAngle * 2.0f * M_PI); + blendFactor = std::clamp(blendFactor, 0.1f, 0.9f); + + Vec4 newcolor = Vec4( + seedColor.r * blendFactor + neighborColor.r * (1.0f - blendFactor), + seedColor.g * (1.0f - blendFactor) + neighborColor.g * blendFactor, + seedColor.b * (0.5f + 0.5f * std::sin(normalizedAngle * 4.0f * M_PI)), 1.0f ); + + newcolor = newcolor.clamp(0.0f, 1.0f); + grid.setColor(neighbor, newcolor); - newseeds.push_back({neighbor, neipos,newcolor}); + newseeds.emplace_back(neighbor, neipos, newcolor); } } - seeds = newseeds; + seeds.clear(); + seeds = std::move(newseeds); } bool exportavi(std::vector> frames, AnimationConfig config) { @@ -134,12 +154,9 @@ int main() { std::vector> seeds = pickSeeds(grid,config); std::vector> frames; - //memory aid - std::unordered_set visited; - for (int i = 0; i < config.totalFrames; ++i){ std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl; - expandPixel(grid,config,seeds, visited); + expandPixel(grid,config,seeds); int width; int height; std::vector frame; diff --git a/util/vectorlogic/vec4.hpp b/util/vectorlogic/vec4.hpp index d0e6c55..f664361 100644 --- a/util/vectorlogic/vec4.hpp +++ b/util/vectorlogic/vec4.hpp @@ -33,6 +33,10 @@ public: return *this; } + Vec4 average(const Vec4& other) const { + return Vec4((x+other.x)/2,(y+other.y)/2,(z+other.z)/2,(w+other.w)/2); + } + Vec4 operator+(const Vec4& other) const { return Vec4(x + other.x, y + other.y, z + other.z, w + other.w); }