-
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.
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
1 parent
f8e5ce6
commit d6c4145
Showing
4 changed files
with
109 additions
and
63 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
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 |
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 |
---|---|---|
@@ -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) |
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 |
---|---|---|
@@ -1,70 +1,51 @@ | ||
#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); | ||
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; | ||
} |