Skip to content

Commit

Permalink
fuck.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBearodactyl committed May 2, 2024
1 parent c516e90 commit 219bfe9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Geode/modify/CCMotionStreak.hpp>
#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/PlayerObject.hpp>
#include <string>
#include "trail_customization/rainbow_trail.hpp"

using namespace geode::prelude;
Expand All @@ -25,9 +26,6 @@ class $modify(PlayLayer) {
RainbowTrail::g += speed / 10;
}

_ccColor3B rainbowColor = RainbowTrail::get_rainbow(0, saturation);
_ccColor3B rainbowColor2 = RainbowTrail::get_rainbow(180, saturation);
_ccColor3B rainbowColor3 = RainbowTrail::get_rainbow(90, saturation);
bool enable = Mod::get()->getSettingValue<bool>("enable");
bool noRegularTrail = Mod::get()->getSettingValue<bool>("no-reg-trail");

Expand All @@ -49,4 +47,4 @@ class $modify(PlayLayer) {
}
}
}
};
};
55 changes: 55 additions & 0 deletions src/trail_customization/rainbow_trail.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "rainbow_trail.hpp"
#include <cmath>
#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;
Expand Down Expand Up @@ -45,6 +47,59 @@ void RainbowTrail::hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float
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) {
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);

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;
}

float RainbowTrail::g = 0;

cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) {
Expand Down
3 changes: 3 additions & 0 deletions src/trail_customization/rainbow_trail.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <Geode/cocos/include/ccTypes.h>
#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;
};

0 comments on commit 219bfe9

Please sign in to comment.