From 8a51ce2f04cf469faf56c084b5f63e1f3a61cecd Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 30 Jan 2021 16:24:36 -0800 Subject: [PATCH] New patterns with the idea of pulling colors from set arrays of color patterns --- src/app/blumen_lumen.cpp | 2 + src/app/foldhaus_app.cpp | 2 - src/app/patterns/blumen_patterns.h | 127 +++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 2 deletions(-) diff --git a/src/app/blumen_lumen.cpp b/src/app/blumen_lumen.cpp index 2fd647d..bde1a00 100644 --- a/src/app/blumen_lumen.cpp +++ b/src/app/blumen_lumen.cpp @@ -70,6 +70,8 @@ BlumenLumen_LoadPatterns(app_state* State) Patterns_PushPattern(Patterns, Pattern_ColorToWhite); Patterns_PushPattern(Patterns, Pattern_Blue); Patterns_PushPattern(Patterns, Pattern_Green); + Patterns_PushPattern(Patterns, Pattern_FlowerColors); + Patterns_PushPattern(Patterns, Pattern_FlowerColorToWhite); } internal gs_data diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index 13111f7..6277cd4 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -74,8 +74,6 @@ UPDATE_AND_RENDER(UpdateAndRender) DEBUG_TRACK_FUNCTION; 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, // 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 diff --git a/src/app/patterns/blumen_patterns.h b/src/app/patterns/blumen_patterns.h index 966587a..c4b3f8e 100644 --- a/src/app/patterns/blumen_patterns.h +++ b/src/app/patterns/blumen_patterns.h @@ -5,6 +5,52 @@ // #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 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); } +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 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 #endif // BLUMEN_PATTERNS_H \ No newline at end of file