New patterns with the idea of pulling colors from set arrays of color patterns

This commit is contained in:
PS 2021-01-30 16:24:36 -08:00
parent 4836f7550d
commit 8a51ce2f04
3 changed files with 129 additions and 2 deletions

View File

@ -70,6 +70,8 @@ BlumenLumen_LoadPatterns(app_state* State)
Patterns_PushPattern(Patterns, Pattern_ColorToWhite); Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
Patterns_PushPattern(Patterns, Pattern_Blue); Patterns_PushPattern(Patterns, Pattern_Blue);
Patterns_PushPattern(Patterns, Pattern_Green); Patterns_PushPattern(Patterns, Pattern_Green);
Patterns_PushPattern(Patterns, Pattern_FlowerColors);
Patterns_PushPattern(Patterns, Pattern_FlowerColorToWhite);
} }
internal gs_data internal gs_data

View File

@ -74,8 +74,6 @@ UPDATE_AND_RENDER(UpdateAndRender)
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
app_state* State = (app_state*)Context->MemoryBase; app_state* State = (app_state*)Context->MemoryBase;
OutputDebugStringA("Test");
// NOTE(Peter): We do this at the beginning because all the render commands are stored in Transient, // NOTE(Peter): We do this at the beginning because all the render commands are stored in Transient,
// and need to persist beyond the end of the UpdateAndRender call. In the release version, we won't // and need to persist beyond the end of the UpdateAndRender call. In the release version, we won't
// zero the Transient arena when we clear it so it wouldn't be a problem, but it is technically // zero the Transient arena when we clear it so it wouldn't be a problem, but it is technically

View File

@ -5,6 +5,52 @@
// //
#ifndef BLUMEN_PATTERNS_H #ifndef BLUMEN_PATTERNS_H
#define FLOWER_COLORS_COUNT 12
pixel FlowerColors[FLOWER_COLORS_COUNT] = {
{ 232,219,88 },
{ 232,219,88 },
{ 232,219,88 },
{ 147,75,176 },
{ 193,187,197 },
{ 223,190,49 },
{ 198,76,65 },
{ 198,76,65 },
{ 198,76,65 },
{ 226,200,17 },
{ 116,126,39 },
{ 61,62,31 }
};
internal pixel
PixelMix(r32 T, pixel A, pixel B)
{
pixel Result = {
LerpU8(T, A.R, B.R),
LerpU8(T, A.G, B.G),
LerpU8(T, A.B, B.B),
};
return Result;
}
internal pixel
GetColor(pixel* Colors, u32 ColorsCount, r32 Percent)
{
Percent = Clamp01(Percent);
u32 LowerIndex = Percent * ColorsCount;
u32 HigherIndex = LowerIndex + 1;
if (HigherIndex >= ColorsCount) HigherIndex = 0;
r32 LowerPercent = (r32)LowerIndex / (r32)ColorsCount;
r32 StepPercent = 1.f / (r32)ColorsCount;
r32 PercentLower = (Percent - LowerPercent) / StepPercent;
pixel Result = PixelMix(PercentLower, Colors[LowerIndex], Colors[HigherIndex]);
return Result;
}
internal void internal void
SolidColorPattern(led_buffer* Leds, pixel Color) SolidColorPattern(led_buffer* Leds, pixel Color)
{ {
@ -28,6 +74,25 @@ Pattern_Green(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Tr
SolidColorPattern(Leds, Green); SolidColorPattern(Leds, Green);
} }
internal void
Pattern_FlowerColors(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
{
r32 CycleTime = 10;
r32 CyclePercent = ModR32(Time, CycleTime) / CycleTime;
pixel CA = GetColor(FlowerColors, FLOWER_COLORS_COUNT, CyclePercent);
pixel CB = GetColor(FlowerColors, FLOWER_COLORS_COUNT, 1.0f - CyclePercent);
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{
v4 P = Leds->Positions[LedIndex];
r32 Pct = (Abs(ModR32(P.y, 150) / 150) + CycleTime) * PiR32;
r32 APct = RemapR32(SinR32(Pct), -1, 1, 0, 1);
Leds->Colors[LedIndex] = PixelMix(APct, CA, CB);
}
}
internal void internal void
TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData) TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
{ {
@ -476,5 +541,67 @@ Pattern_ColorToWhite(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_ar
} }
} }
internal void
Pattern_FlowerColorToWhite(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
{
r32 FadeBottomBase = 50;
r32 FadeTop = 125;
for (u32 StripIndex = 0; StripIndex < Assembly.StripCount; StripIndex++)
{
v2_strip Strip = Assembly.Strips[StripIndex];
r32 FlowerSpread = .8f;
r32 FlowerOffset = 0;
if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "center"))
{
FlowerOffset = 1;
}
else if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "right"))
{
FlowerOffset = 2;
}
FlowerOffset *= FlowerSpread;
r32 PercentCycle = ModR32(Time + FlowerOffset, 10) / 10;
r32 FadeBottom = FadeBottomBase + RemapR32(SinR32((PercentCycle * 4) * TauR32), -1, 1, -50, 50);
v4 TopRGB = WhiteV4;
pixel TopColor = V4ToRGBPixel(TopRGB);
for (u32 i = 0; i < Strip.LedCount; i++)
{
u32 LedIndex = Strip.LedLUT[i];
v4 P = Leds->Positions[LedIndex];
pixel FinalColor = {};
if (P.y > FadeTop)
{
FinalColor = TopColor;
}
else
{
r32 B = RemapR32(SinR32((P.y / 15.f) + (PercentCycle * TauR32)), -1, 1, .5f, 1.f);
r32 HNoise = RemapR32(SinR32((P.y / 31.f) + (PercentCycle * TauR32)), -1, 1, 0.f, 1.f);
pixel BottomColor = GetColor(FlowerColors, FLOWER_COLORS_COUNT, (PercentCycle + HNoise) / 2);
if (P.y < FadeBottom)
{
FinalColor = BottomColor;
}
else if (P.y >= FadeBottom && P.y <= FadeTop)
{
r32 FadePct = RemapR32(P.y, FadeBottom, FadeTop, 0, 1);
FinalColor = PixelMix(FadePct, BottomColor, TopColor);
}
}
Leds->Colors[LedIndex] = FinalColor;
}
}
}
#define BLUMEN_PATTERNS_H #define BLUMEN_PATTERNS_H
#endif // BLUMEN_PATTERNS_H #endif // BLUMEN_PATTERNS_H