Skip to content

Commit

Permalink
refactor and optimize
Browse files Browse the repository at this point in the history
cast the values of `out.r`, `out.g`, and `out.b` to `GLubyte`
cast the values of `hue` and `sat` to float
  • Loading branch information
TheBearodactyl committed Apr 29, 2024
1 parent f8e5ce6 commit 7c7f071
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 65 deletions.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: true
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_COMPILER_LAUNCHER "sccache")
set(CMAKE_C_COMPILER_LAUNCHER "sccache")

project(gay-wave-trail VERSION 1.0.0)

Expand Down
3 changes: 2 additions & 1 deletion about.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Transform your wave trail into a
# _***R A G I N G H O M O S E X U A L***_

thanks to shadowforce78 for the hsv_to_rgb logic :D
thanks to shadowforce78 for the hsv_to_rgb logic :D\
(update: the hsv_to_rgb logic is now of my own making :3)
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mac": "2.200",
"android": "2.205"
},
"version": "v1.0.15",
"version": "v1.0.16",
"id": "the_bearodactyl.gay-wave-trail",
"name": "Gay Wave Trail",
"developer": "The Bearodactyl",
Expand Down
104 changes: 43 additions & 61 deletions src/trail_customization/rainbow_trail.cpp
Original file line number Diff line number Diff line change
@@ -1,70 +1,52 @@
#include "rainbow_trail.hpp"

#include <cmath>

void RainbowTrail::hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV) {
float fC = fV * fS; // Chroma
float fHPrime = fmod(fH / 60.0, 6);
float fX = fC * (1 - fabs(fmod(fHPrime, 2) - 1));
float fM = fV - fC;

int hue_segment = static_cast<int>(fHPrime);
switch (hue_segment) {
case 0:
fR = fC;
fG = fX;
fB = 0;
break;
case 1:
fR = fX;
fG = fC;
fB = 0;
break;
case 2:
fR = 0;
fG = fC;
fB = fX;
break;
case 3:
fR = 0;
fG = fX;
fB = fC;
break;
case 4:
fR = fX;
fG = 0;
fB = fC;
break;
case 5:
fR = fC;
fG = 0;
fB = fX;
break;
default:
fR = 0;
fG = 0;
fB = 0;
break;
}

fR += fM;
fG += fM;
fB += fM;
float fC = fV * fS, fHPrime = fmodf(fH / 60.0f, 6), fX = fC * ( 1 - fabsf(fmodf(fHPrime, 2) - 1));
int iHue = static_cast<int>(fHPrime);
// ternary operators are fucking awesome.
fR = ( iHue == 0 )
? fC
: ( iHue == 1 )
? fX
: ( iHue == 4 )
? fX
: ( iHue == 5 )
? fC
: 0;
fG = ( iHue == 1 )
? fC
: ( iHue == 2 )
? fC
: ( iHue == 3 )
? fX
: 0;
fB = ( iHue == 3 )
? fC
: ( iHue == 4 )
? fC
: ( iHue == 5 )
? fX
: 0;
float fM = fV - fC;
fR += fM;
fG += fM;
fB += fM;
}

float RainbowTrail::g = 0;

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

float hue = fmod(g + offset, 360);
float sat = saturation / 100.0;
float vc = 1;
hsv_to_rgb(R, G, B, hue, sat, vc);

cocos2d::_ccColor3B out;
out.r = R * 255;
out.g = G * 255;
out.b = B * 255;
return out;
}
float R, G, B;

float hue = static_cast<float>(fmod(g + offset, 360));
float sat = static_cast<float>(saturation / 100.0);
float vc = 1;
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;
}

0 comments on commit 7c7f071

Please sign in to comment.