-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move the rainbow trail shit to its own header/source file combo - Use a ternary for mirroring the players instead of if/else - Use a switch statement for HSVtoRGB instead of if/else if/else - Use snake_case in some places
- Loading branch information
1 parent
31176a2
commit de46cd9
Showing
6 changed files
with
116 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#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 RainbowTrail::g = 0; | ||
|
||
cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) { | ||
float R; | ||
float G; | ||
float 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <Geode/cocos/include/ccTypes.h> | ||
|
||
class RainbowTrail { | ||
public: | ||
static void hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV); | ||
static cocos2d::_ccColor3B get_rainbow(float offset, float saturation); | ||
static float g; | ||
}; |