Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoHueBlend.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoHueBlend provides method objects that can be directly consumed by
3 blend template functions in HslColor and HsbColor
4 
5 Written by Michael C. Miller.
6 
7 I invest time and resources providing this open source code,
8 please support me by dontating (see https://github.com/Makuna)
9 
10 -------------------------------------------------------------------------
11 This file is part of the LUMITRONIX_iFlex_Workshop library.
12 
13 LumitronixIFlexBus is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as
15 published by the Free Software Foundation, either version 3 of
16 the License, or (at your option) any later version.
17 
18 LumitronixIFlexBus is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 
23 You should have received a copy of the GNU Lesser General Public
24 License along with LumitronixIFlex. If not, see
25 <http://www.gnu.org/licenses/>.
26 -------------------------------------------------------------------------*/
27 #pragma once
28 
30 {
31 protected:
32  static float FixWrap(float value)
33  {
34  if (value < 0.0f)
35  {
36  value += 1.0f;
37  }
38  else if (value > 1.0f)
39  {
40  value -= 1.0f;
41  }
42  return value;
43  }
44 };
45 
47 {
48 public:
49  static float HueBlend(float left, float right, float progress)
50  {
51  float delta = right - left;
52  float base = left;
53  if (delta > 0.5f)
54  {
55  base = right;
56  delta = 1.0f - delta;
57  progress = 1.0f - progress;
58  }
59  else if (delta < -0.5f)
60  {
61  delta = 1.0f + delta;
62  }
63  return FixWrap(base + (delta) * progress);
64  };
65 };
66 
68 {
69 public:
70  static float HueBlend(float left, float right, float progress)
71  {
72  float delta = right - left;
73  float base = left;
74  if (delta < 0.5f && delta >= 0.0f)
75  {
76  base = right;
77  delta = 1.0f - delta;
78  progress = 1.0f - progress;
79  }
80  else if (delta > -0.5f && delta < 0.0f)
81  {
82  delta = 1.0f + delta;
83  }
84  return FixWrap(base + delta * progress);
85  };
86 };
87 
89 {
90 public:
91  static float HueBlend(float left, float right, float progress)
92  {
93  float delta = right - left;
94  float base = left;
95  if (delta < 0.0f)
96  {
97  delta = 1.0f + delta;
98  }
99 
100  return FixWrap(base + delta * progress);
101  };
102 };
103 
105 {
106 public:
107  static float HueBlend(float left, float right, float progress)
108  {
109  float delta = right - left;
110  float base = left;
111  if (delta > 0.0f)
112  {
113  delta = delta - 1.0f;
114  }
115 
116  return FixWrap(base + delta * progress);
117  };
118 };
Definition: NeoHueBlend.h:30
static float FixWrap(float value)
Definition: NeoHueBlend.h:32
Definition: NeoHueBlend.h:89
static float HueBlend(float left, float right, float progress)
Definition: NeoHueBlend.h:91
Definition: NeoHueBlend.h:105
static float HueBlend(float left, float right, float progress)
Definition: NeoHueBlend.h:107
Definition: NeoHueBlend.h:68
static float HueBlend(float left, float right, float progress)
Definition: NeoHueBlend.h:70
Definition: NeoHueBlend.h:47
static float HueBlend(float left, float right, float progress)
Definition: NeoHueBlend.h:49