Skip to content

Commit

Permalink
add custom color support using gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBearodactyl committed May 12, 2024
1 parent 5dc1fc0 commit 2cb4682
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 135 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 32 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down
92 changes: 65 additions & 27 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,89 @@
#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/PlayerObject.hpp>
#include <string>
#include <cocos2d.h>
#include <cmath>

#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<double>("speed");
float saturation = Mod::get()->getSettingValue<double>("saturation");
bool mirror_players = Mod::get()->getSettingValue<bool>("mirror-players");
PlayLayer::postUpdate(p0);

if (RainbowTrail::g >= 360) {
RainbowTrail::g = 0;
} else {
RainbowTrail::g += speed / 10;
}
float speed = Mod::get()->getSettingValue<double>("speed");
float saturation = Mod::get()->getSettingValue<double>("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<bool>("mirror-players");
bool use_gradient = Mod::get()->getSettingValue<bool>("use-gradient");
bool enable = Mod::get()->getSettingValue<bool>("enable");
bool noRegularTrail = Mod::get()->getSettingValue<bool>("no-reg-trail");

bool enable = Mod::get()->getSettingValue<bool>("enable");
bool noRegularTrail = Mod::get()->getSettingValue<bool>("no-reg-trail");
ccColor3B color1 = Mod::get()->getSettingValue<ccColor3B>("color-one");
ccColor3B color2 = Mod::get()->getSettingValue<ccColor3B>("color-two");
ccColor3B color3 = Mod::get()->getSettingValue<ccColor3B>("color-three");
ccColor3B color4 = Mod::get()->getSettingValue<ccColor3B>("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);
}
}
}
}
};
127 changes: 28 additions & 99 deletions src/trail_customization/rainbow_trail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,13 @@
#include <vector>
#include <cstdint>

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<float>(static_cast<double>(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<uint32_t> &hex_colors, float offset, float saturation) {
cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) {
float R, G, B;

int num_colors = static_cast<int>(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<unsigned int>(static_cast<int>(fmod(g + offset, num_colors)))], hue, sat, vc);
sat = static_cast<float>(static_cast<double>(saturation) / 100.0);

hsv_to_rgb(R, G, B, hue, sat, vc);
float hue = static_cast<float>(fmod(ColorUtils::owo + offset, 360));
float sat = static_cast<float>(static_cast<double>(saturation) / 100.0);
float vc = 1;
ColorUtils::hsv_to_rgb(R, G, B, hue, sat, vc);

cocos2d::_ccColor3B out{};
out.r = static_cast<GLubyte>(R * 255);
Expand All @@ -100,19 +18,30 @@ cocos2d::_ccColor3B RainbowTrail::get_custom_rainbow(const std::vector<uint32_t>
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<int>(t / 90.0f);

cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) {
float R, G, B;
cocos2d::_ccColor3B out;

float hue = static_cast<float>(fmod(g + offset, 360));
float sat = static_cast<float>(static_cast<double>(saturation) / 100.0);
float vc = 1;
hsv_to_rgb(R, G, B, hue, sat, vc);
out.r = static_cast<GLubyte>(
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<GLubyte>(R * 255);
out.g = static_cast<GLubyte>(G * 255);
out.b = static_cast<GLubyte>(B * 255);
return out;
out.g = static_cast<GLubyte>(
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<GLubyte>(
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;
}
5 changes: 2 additions & 3 deletions src/trail_customization/rainbow_trail.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <Geode/cocos/include/ccTypes.h>
#include "../utils/color_utils.hpp"
#include <vector>

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<uint32_t> &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);
};
Loading

0 comments on commit 2cb4682

Please sign in to comment.