From 2cb4682f1b70a2a029d439b1de233eef5fb7a162 Mon Sep 17 00:00:00 2001 From: The Motherfucking Bearodactyl Date: Sun, 12 May 2024 15:43:44 -0500 Subject: [PATCH] add custom color support using gradients --- CMakeLists.txt | 9 +- mod.json | 34 +++++- src/main.cpp | 92 +++++++++++----- src/trail_customization/rainbow_trail.cpp | 127 +++++----------------- src/trail_customization/rainbow_trail.hpp | 5 +- src/utils/color_utils.cpp | 80 ++++++++++++++ src/utils/color_utils.hpp | 10 ++ 7 files changed, 222 insertions(+), 135 deletions(-) create mode 100644 src/utils/color_utils.cpp create mode 100644 src/utils/color_utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 808572f..a09d714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,17 +7,18 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) project(gay-wave-trail VERSION 1.0.0) file(GLOB_RECURSE SOURCES - src/*.cpp - src/trail_customization/*.cpp + src/*.cpp + src/utils/*.cpp + src/trail_customization/*.cpp ) add_library(${PROJECT_NAME} SHARED ${SOURCES}) if (NOT DEFINED ENV{GEODE_SDK}) message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode") -else() +else () message(STATUS "Found Geode: $ENV{GEODE_SDK}") -endif() +endif () add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode) diff --git a/mod.json b/mod.json index af1851a..4aa8ab5 100644 --- a/mod.json +++ b/mod.json @@ -1,11 +1,11 @@ { - "geode": "2.0.0-beta.25", + "geode": "2.0.0-beta.26", "gd": { "win": "2.204", "mac": "2.200", "android": "2.205" }, - "version": "v1.0.16", + "version": "v1.0.17", "id": "the_bearodactyl.gay-wave-trail", "name": "Gay Wave Trail", "developer": "The Bearodactyl", @@ -45,6 +45,12 @@ "type": "bool", "default": true }, + "use-gradient": { + "name": "Use a gradient instead of a rainbow :D", + "description": "now with 4 colors! full 256\ncolor rainbow NO MORE", + "type": "bool", + "default": false + }, "no-reg-trail": { "name": "THE\nDE-REGULARINATOR\n2000", "description": "\n bye-bye regular trail :3", @@ -56,6 +62,30 @@ "description": "\nfood processors are better than blenders anyways", "type": "bool", "default": true + }, + "color-one": { + "name": "Wave trail color #1", + "description": "G R A D I E N T S A R E F U N", + "type": "color", + "default": "#FFFFFF" + }, + "color-two": { + "name": "Wave trail color #2", + "description": "G R A D I E N T S A R E F U N", + "type": "color", + "default": "#FFFFFF" + }, + "color-three": { + "name": "Wave trail color #3", + "description": "G R A D I E N T S A R E F U N", + "type": "color", + "default": "#FFFFFF" + }, + "color-four": { + "name": "Wave trail color #4", + "description": "G R A D I E N T S A R E F U N", + "type": "color", + "default": "#FFFFFF" } }, "repository": "https://gitlab.com/TheBearodactyl/gay-wave-trail.git" diff --git a/src/main.cpp b/src/main.cpp index 98f45e7..cb65191 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,51 +4,89 @@ #include #include #include +#include +#include + #include "trail_customization/rainbow_trail.hpp" using namespace geode::prelude; +using namespace cocos2d; + +float phase; class $modify(PlayerObject) { void flashPlayer(float p0, float p1, cocos2d::ccColor3B mainColor, cocos2d::ccColor3B secondColor) {} }; class $modify(PlayLayer) { - void postUpdate(float p0) { - PlayLayer::postUpdate(p0); + void postUpdate(float p0) { - float speed = Mod::get()->getSettingValue("speed"); - float saturation = Mod::get()->getSettingValue("saturation"); - bool mirror_players = Mod::get()->getSettingValue("mirror-players"); + PlayLayer::postUpdate(p0); - if (RainbowTrail::g >= 360) { - RainbowTrail::g = 0; - } else { - RainbowTrail::g += speed / 10; - } + float speed = Mod::get()->getSettingValue("speed"); + float saturation = Mod::get()->getSettingValue("saturation"); - _ccColor3B rainbowColor = RainbowTrail::get_rainbow(0, saturation); - _ccColor3B rainbowColor2 = RainbowTrail::get_rainbow(180, saturation); - _ccColor3B rainbowColor3 = RainbowTrail::get_rainbow(90, saturation); + bool mirror_players = Mod::get()->getSettingValue("mirror-players"); + bool use_gradient = Mod::get()->getSettingValue("use-gradient"); + bool enable = Mod::get()->getSettingValue("enable"); + bool noRegularTrail = Mod::get()->getSettingValue("no-reg-trail"); - bool enable = Mod::get()->getSettingValue("enable"); - bool noRegularTrail = Mod::get()->getSettingValue("no-reg-trail"); + ccColor3B color1 = Mod::get()->getSettingValue("color-one"); + ccColor3B color2 = Mod::get()->getSettingValue("color-two"); + ccColor3B color3 = Mod::get()->getSettingValue("color-three"); + ccColor3B color4 = Mod::get()->getSettingValue("color-four"); - if (m_player1->m_isDart && noRegularTrail) { - m_player1->m_regularTrail->setVisible(false); - } + if ( ColorUtils::owo >= 360 ) { + ColorUtils::owo = 0; + } else { + ColorUtils::owo += speed / 10; + } + + phase = fmod(phase + speed, 360.f); + bool p2 = true; + + _ccColor3B rainbowColor = RainbowTrail::get_rainbow(0, saturation); + _ccColor3B rainbowColor2 = RainbowTrail::get_rainbow(180, saturation); - if (m_player2->m_isDart && noRegularTrail) { - m_player2->m_regularTrail->setVisible(false); + _ccColor3B gradientColor = RainbowTrail::get_gradient(phase, 0.0f, false, color1, color2, color3, color4); + _ccColor3B gradientColor2 = RainbowTrail::get_gradient(phase, 0.0f, false, color4, color3, color2, color1); + + if ( m_player1->m_isDart && noRegularTrail ) { + m_player1->m_regularTrail + ->setVisible(false); + } + + if ( m_player2->m_isDart && noRegularTrail ) { + m_player2->m_regularTrail + ->setVisible(false); + } + + if ( enable ) { + if ( ! use_gradient ) { + if ( m_player1->m_waveTrail ) { + m_player1->m_waveTrail + ->setColor(rainbowColor); } - if (enable) { - if (m_player1->m_waveTrail) { - m_player1->m_waveTrail->setColor(rainbowColor); - } + if ( m_player2->m_waveTrail ) { + m_player2->m_waveTrail + ->setColor(! mirror_players + ? rainbowColor2 + : rainbowColor); + } + } else { + if ( m_player1->m_waveTrail ) { + m_player1->m_waveTrail + ->setColor(gradientColor); + } - if (m_player2->m_waveTrail) { - m_player2->m_waveTrail->setColor(!mirror_players ? rainbowColor2 : rainbowColor); - } + if ( m_player2->m_waveTrail ) { + m_player2->m_waveTrail + ->setColor(! mirror_players + ? gradientColor + : gradientColor2); } + } } + } }; diff --git a/src/trail_customization/rainbow_trail.cpp b/src/trail_customization/rainbow_trail.cpp index b3853f4..2d17389 100644 --- a/src/trail_customization/rainbow_trail.cpp +++ b/src/trail_customization/rainbow_trail.cpp @@ -3,95 +3,13 @@ #include #include -void RainbowTrail::hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV) { - float c = fV * fS; - float x = static_cast(static_cast(c) * ( 1 - std::abs(std::fmod(fH / 60.0f, 2) - 1))); - float m = fV - c; - - fR = ( fH < 60.0f ) - ? c - : ( fH < 120.0f ) - ? x - : ( fH < 180.0f ) - ? 0 - : ( fH < 240.0f ) - ? 0 - : ( fH < 300.0f ) - ? x - : c; - fG = ( fH < 60.0f ) - ? x - : ( fH < 120.0f ) - ? c - : ( fH < 180.0f ) - ? c - : ( fH < 240.0f ) - ? x - : ( fH < 300.0f ) - ? 0 - : 0; - fB = ( fH < 60.0f ) - ? 0 - : ( fH < 120.0f ) - ? 0 - : ( fH < 180.0f ) - ? x - : ( fH < 240.0f ) - ? c - : ( fH < 300.0f ) - ? c - : x; - - fR += m; - fG += m; - fB += m; -} - -void RainbowTrail::hex_to_hsv(uint32_t hex, float &h, float &s, float &v) { - float r = (( hex >> 16 ) & 0xFF ) / 255.0f; - float g = (( hex >> 8 ) & 0xFF ) / 255.0f; - float b = ( hex & 0xFF ) / 255.0f; - - float max = std::max(std::max(r, g), b); - float min = std::min(std::min(r, g), b); - v = max; - - float delta = max - min; - if ( max != 0.0f ) { - s = delta / max; - } else { - s = 0.0f; - h = 0.0f; - return; - } - - if ( r == max ) { - h = ( g - b ) / delta; - } else if ( g == max ) { - h = 2.0f + ( b - r ) / delta; - } else { - h = 4.0f + ( r - g ) / delta; - } - - h *= 60.0f; - if ( h < 0.0f ) { - h += 360.0f; - } -} - -cocos2d::_ccColor3B RainbowTrail::get_custom_rainbow(const std::vector &hex_colors, float offset, float saturation) { +cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) { float R, G, B; - int num_colors = static_cast(hex_colors.size()); - if ( num_colors == 0 ) { - return cocos2d::_ccColor3B{0, 0, 0}; - } - - float hue, sat, vc = 1.0f; - hex_to_hsv(hex_colors[static_cast(static_cast(fmod(g + offset, num_colors)))], hue, sat, vc); - sat = static_cast(static_cast(saturation) / 100.0); - - hsv_to_rgb(R, G, B, hue, sat, vc); + float hue = static_cast(fmod(ColorUtils::owo + offset, 360)); + float sat = static_cast(static_cast(saturation) / 100.0); + float vc = 1; + ColorUtils::hsv_to_rgb(R, G, B, hue, sat, vc); cocos2d::_ccColor3B out{}; out.r = static_cast(R * 255); @@ -100,19 +18,30 @@ cocos2d::_ccColor3B RainbowTrail::get_custom_rainbow(const std::vector return out; } -float RainbowTrail::g = 0; +cocos2d::_ccColor3B RainbowTrail::get_gradient(float &phase, float offset, bool smooth, ccColor3B c1, ccColor3B c2, ccColor3B c3, ccColor3B c4) { + float t = fmodf(phase + offset, 360.0f); + float y = t / 90.0f; + int quadrant = static_cast(t / 90.0f); -cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) { - float R, G, B; + cocos2d::_ccColor3B out; - float hue = static_cast(fmod(g + offset, 360)); - float sat = static_cast(static_cast(saturation) / 100.0); - float vc = 1; - hsv_to_rgb(R, G, B, hue, sat, vc); + out.r = static_cast( + quadrant == 0 ? c1.r + (c2.r - c1.r) * y + : quadrant == 1 ? c2.r + (c3.r - c2.r) * (y - 1.0f) + : quadrant == 2 ? c3.r + (c4.r - c3.r) * (y - 2.0f) + : c4.r + (c1.r - c4.r) * (y - 3.0f)); - cocos2d::_ccColor3B out{}; - out.r = static_cast(R * 255); - out.g = static_cast(G * 255); - out.b = static_cast(B * 255); - return out; + out.g = static_cast( + quadrant == 0 ? c1.g + (c2.g - c1.g) * y + : quadrant == 1 ? c2.g + (c3.g - c2.g) * (y - 1.0f) + : quadrant == 2 ? c3.g + (c4.g - c3.g) * (y - 2.0f) + : c4.g + (c1.g - c4.g) * (y - 3.0f)); + + out.b = static_cast( + quadrant == 0 ? c1.b + (c2.b - c1.b) * y + : quadrant == 1 ? c2.b + (c3.b - c2.b) * (y - 1.0f) + : quadrant == 2 ? c3.b + (c4.b - c3.b) * (y - 2.0f) + : c4.b + (c1.b - c4.b) * (y - 3.0f)); + + return out; } diff --git a/src/trail_customization/rainbow_trail.hpp b/src/trail_customization/rainbow_trail.hpp index a3e5862..a70e73d 100644 --- a/src/trail_customization/rainbow_trail.hpp +++ b/src/trail_customization/rainbow_trail.hpp @@ -1,13 +1,12 @@ #pragma once #include +#include "../utils/color_utils.hpp" #include class RainbowTrail { public: - static void hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV); - static void hex_to_hsv(uint32_t hex, float &h, float &s, float &v); static cocos2d::_ccColor3B get_rainbow(float offset, float saturation); cocos2d::_ccColor3B get_custom_rainbow(const std::vector &hex_colors, float offset, float saturation); - static float g; + static cocos2d::_ccColor3B get_gradient(float &phase, float offset, bool smooth, ccColor3B c1, ccColor3B c2, ccColor3B c3, ccColor3B c4); }; \ No newline at end of file diff --git a/src/utils/color_utils.cpp b/src/utils/color_utils.cpp new file mode 100644 index 0000000..8a61189 --- /dev/null +++ b/src/utils/color_utils.cpp @@ -0,0 +1,80 @@ +#include "color_utils.hpp" +#include + +void ColorUtils::hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV) { + float c = fV * fS; + float x = static_cast(static_cast(c) * ( 1 - std::abs(std::fmod(fH / 60.0f, 2) - 1))); + float m = fV - c; + + fR = ( fH < 60.0f ) + ? c + : ( fH < 120.0f ) + ? x + : ( fH < 180.0f ) + ? 0 + : ( fH < 240.0f ) + ? 0 + : ( fH < 300.0f ) + ? x + : c; + fG = ( fH < 60.0f ) + ? x + : ( fH < 120.0f ) + ? c + : ( fH < 180.0f ) + ? c + : ( fH < 240.0f ) + ? x + : ( fH < 300.0f ) + ? 0 + : 0; + fB = ( fH < 60.0f ) + ? 0 + : ( fH < 120.0f ) + ? 0 + : ( fH < 180.0f ) + ? x + : ( fH < 240.0f ) + ? c + : ( fH < 300.0f ) + ? c + : x; + + fR += m; + fG += m; + fB += m; +} + +float ColorUtils::owo = 0; + +void ColorUtils::hex_to_hsv(uint32_t hex, float &h, float &s, float &v) { + float r = (( hex >> 16 ) & 0xFF ) / 255.0f; + float g = (( hex >> 8 ) & 0xFF ) / 255.0f; + float b = ( hex & 0xFF ) / 255.0f; + + float max = std::max(std::max(r, g), b); + float min = std::min(std::min(r, g), b); + v = max; + + float delta = max - min; + if ( max != 0.0f ) { + s = delta / max; + } else { + s = 0.0f; + h = 0.0f; + return; + } + + if ( r == max ) { + h = ( g - b ) / delta; + } else if ( g == max ) { + h = 2.0f + ( b - r ) / delta; + } else { + h = 4.0f + ( r - g ) / delta; + } + + h *= 60.0f; + if ( h < 0.0f ) { + h += 360.0f; + } +} diff --git a/src/utils/color_utils.hpp b/src/utils/color_utils.hpp new file mode 100644 index 0000000..b45041d --- /dev/null +++ b/src/utils/color_utils.hpp @@ -0,0 +1,10 @@ +#include + +using namespace cocos2d; + +class ColorUtils { +public: + static void hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV); + static void hex_to_hsv(uint32_t hex, float &h, float &s, float &v); + static float owo; +}; \ No newline at end of file