more blumen explorations

This commit is contained in:
Peter Slattery 2021-01-23 15:58:05 -08:00
parent c921e37df3
commit 26caed68a4
6 changed files with 124 additions and 44 deletions

View File

@ -5,6 +5,10 @@
// //
#ifndef BLUMEN_LUMEN_CPP #ifndef BLUMEN_LUMEN_CPP
// TODO(pjs):
// - need to request opening a network port and getting messages from it pumped into CustomUpdate
//
struct foo_ struct foo_
{ {
u32 Heyo; u32 Heyo;
@ -23,21 +27,35 @@ BlumenLumen_CustomInit(app_state* State, context Context)
foo_* MyFoo = (foo_*)Result.Memory; foo_* MyFoo = (foo_*)Result.Memory;
MyFoo->Heyo = 5; MyFoo->Heyo = 5;
#if 1
gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog);
#endif
{ // Animation PLAYGROUND { // Animation PLAYGROUND
animation Anim0 = {0};
Anim0.Name = PushStringF(&State->Permanent, 256, "test_anim_zero");
Anim0.Layers = AnimLayerArray_Create(State->AnimationSystem.Storage, 8);
Anim0.Blocks_ = AnimBlockArray_Create(State->AnimationSystem.Storage, 8);
Anim0.PlayableRange.Min = 0;
Anim0.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
Animation_AddLayer(&Anim0, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
animation Anim = {0}; Animation_AddBlock(&Anim0, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(5), 0);
Anim.Name = PushStringF(&State->Permanent, 256, "test_anim_one");
Anim.Layers = AnimLayerArray_Create(State->AnimationSystem.Storage, 8);
Anim.Blocks_ = AnimBlockArray_Create(State->AnimationSystem.Storage, 8);
Anim.PlayableRange.Min = 0;
Anim.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
Animation_AddLayer(&Anim, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
Animation_AddLayer(&Anim, MakeString("Color Layer"), BlendMode_Multiply, &State->AnimationSystem);
Animation_AddLayer(&Anim, MakeString("Sparkles"), BlendMode_Add, &State->AnimationSystem);
Animation_AddBlock(&Anim, 0, Anim.PlayableRange.Max, Patterns_IndexToHandle(5), 0); AnimationArray_Push(&State->AnimationSystem.Animations, Anim0);
AnimationArray_Push(&State->AnimationSystem.Animations, Anim); animation Anim1 = {0};
Anim1.Name = PushStringF(&State->Permanent, 256, "test_anim_one");
Anim1.Layers = AnimLayerArray_Create(State->AnimationSystem.Storage, 8);
Anim1.Blocks_ = AnimBlockArray_Create(State->AnimationSystem.Storage, 8);
Anim1.PlayableRange.Min = 0;
Anim1.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
Animation_AddLayer(&Anim1, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
Animation_AddBlock(&Anim1, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(5), 0);
AnimationArray_Push(&State->AnimationSystem.Animations, Anim1);
State->AnimationSystem.TimelineShouldAdvance = true; State->AnimationSystem.TimelineShouldAdvance = true;
} // End Animation Playground } // End Animation Playground

View File

@ -225,5 +225,13 @@ AssemblyStrip_HasTagValue(v2_strip Strip, u64 NameHash, u64 ValueHash)
return Result; return Result;
} }
internal bool
AssemblyStrip_HasTagValueSLOW(v2_strip Strip, char* Name, char* Value)
{
u64 NameHash = HashDJB2ToU32(Name);
u64 ValueHash = HashDJB2ToU32(Value);
return AssemblyStrip_HasTagValue(Strip, NameHash, ValueHash);
}
#define FOLDHAUS_ASSEMBLY_H #define FOLDHAUS_ASSEMBLY_H
#endif // FOLDHAUS_ASSEMBLY_H #endif // FOLDHAUS_ASSEMBLY_H

View File

@ -26,6 +26,7 @@ ClearAndPushPatterns(animation_pattern_array* Patterns)
Patterns_PushPattern(Patterns, Pattern_LighthouseRainbow); Patterns_PushPattern(Patterns, Pattern_LighthouseRainbow);
Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow); Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow);
Patterns_PushPattern(Patterns, Pattern_GrowAndFade); Patterns_PushPattern(Patterns, Pattern_GrowAndFade);
Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
} }
RELOAD_STATIC_DATA(ReloadStaticData) RELOAD_STATIC_DATA(ReloadStaticData)
@ -52,7 +53,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
State->CommandQueue = CommandQueue_Create(&State->Permanent, 32); State->CommandQueue = CommandQueue_Create(&State->Permanent, 32);
State->Patterns = Patterns_Create(&State->Permanent, 10); State->Patterns = Patterns_Create(&State->Permanent, 32);
ClearAndPushPatterns(&State->Patterns); ClearAndPushPatterns(&State->Patterns);
interface_config IConfig = {0}; interface_config IConfig = {0};
@ -85,11 +86,6 @@ INITIALIZE_APPLICATION(InitializeApplication)
ReloadStaticData(Context, GlobalDebugServices); ReloadStaticData(Context, GlobalDebugServices);
#if 1
gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog);
#endif
animation_system_desc AnimSysDesc = {}; animation_system_desc AnimSysDesc = {};
AnimSysDesc.Storage = &State->Permanent; AnimSysDesc.Storage = &State->Permanent;
AnimSysDesc.AnimArrayCount = 32; AnimSysDesc.AnimArrayCount = 32;

View File

@ -391,5 +391,67 @@ Pattern_GrowAndFade(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_are
} }
} }
internal void
Pattern_ColorToWhite(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, -32.f, 32.f);
v4 BottomRGB = HSVToRGB(v4{ (PercentCycle * 360) + HNoise, 1, B, 1 });
if (P.y < FadeBottom)
{
FinalColor = V4ToRGBPixel(BottomRGB);
}
else if (P.y >= FadeBottom && P.y <= FadeTop)
{
r32 FadePct = RemapR32(P.y, FadeBottom, FadeTop, 0, 1);
v4 MixRGB = V4Lerp(FadePct, BottomRGB, TopRGB);
FinalColor = V4ToRGBPixel(MixRGB);
}
}
Leds->Colors[LedIndex] = FinalColor;
}
}
}
#define BLUMEN_PATTERNS_H #define BLUMEN_PATTERNS_H
#endif // BLUMEN_PATTERNS_H #endif // BLUMEN_PATTERNS_H

View File

@ -685,34 +685,34 @@ V4Cross(v4 A, v4 B)
} }
internal v2 internal v2
V2Lerp(v2 A, v2 B, r32 T) V2Lerp(r32 T, v2 A, v2 B)
{ {
v2 Result = v2{ v2 Result = v2{
LerpR32(A.x, B.x, T), LerpR32(T, A.x, B.x),
LerpR32(A.y, B.y, T), LerpR32(T, A.y, B.y),
}; };
return Result; return Result;
} }
internal v3 internal v3
V3Lerp(v3 A, v3 B, r32 T) V3Lerp(r32 T, v3 A, v3 B)
{ {
v3 Result = v3{ v3 Result = v3{
LerpR32(A.x, B.x, T), LerpR32(T, A.x, B.x),
LerpR32(A.y, B.y, T), LerpR32(T, A.y, B.y),
LerpR32(A.z, B.z, T), LerpR32(T, A.z, B.z),
}; };
return Result; return Result;
} }
internal v4 internal v4
V4Lerp(v4 A, v4 B, r32 T) V4Lerp(r32 T, v4 A, v4 B)
{ {
v4 Result = v4{ v4 Result = v4{
LerpR32(A.x, B.x, T), LerpR32(T, A.x, B.x),
LerpR32(A.y, B.y, T), LerpR32(T, A.y, B.y),
LerpR32(A.z, B.z, T), LerpR32(T, A.z, B.z),
LerpR32(A.w, B.w, T), LerpR32(T, A.w, B.w),
}; };
return Result; return Result;
} }

View File

@ -172,7 +172,6 @@ int main(int ArgCount, char** Args)
gs_string OutputBuffer = PushString(Ctx.Transient, MB(4)); gs_string OutputBuffer = PushString(Ctx.Transient, MB(4));
char* ComPort = "\\\\.\\COM3";
WriteAssemblyUARTOpen(&OutputBuffer, WriteAssemblyUARTOpen(&OutputBuffer,
"Blumen Lumen - Silver Spring", "Blumen Lumen - Silver Spring",
100, 100,
@ -181,37 +180,34 @@ int main(int ArgCount, char** Args)
""); "");
u32 StemChannels[] = { FSC(2, 1), FSC(2, 2), FSC(2, 3), FSC(2, 4), FSC(2, 5), FSC(2, 6) }; u32 StemChannels[] = { FSC(2, 1), FSC(2, 2), FSC(2, 3), FSC(2, 4), FSC(2, 5), FSC(2, 6) };
u32 BloomOuterChannels[] = { FSC(1, 0), FSC(1, 1), FSC(1, 2), FSC(1, 3), FSC(1, 4), FSC(1, 5), FSC(1, 6), FSC(1, 7), FSC(2, 7) }; u32 BloomOuterChannels[] = { FSC(1, 0), FSC(1, 1), FSC(1, 2), FSC(1, 3), FSC(1, 4), FSC(1, 5), FSC(1, 6), FSC(1, 7), FSC(2, 0) };
u32 BloomInnerChannels[] = { FSC(0, 0), FSC(0, 1), FSC(0, 2), FSC(0, 3), FSC(0, 4), FSC(0, 5) }; u32 BloomInnerChannels[] = { FSC(0, 0), FSC(0, 1), FSC(0, 2), FSC(0, 3), FSC(0, 4), FSC(0, 5) };
flower_desc F0 = {}; flower_desc F0 = {};
F0.Pos = v3{-1, 0, 0}; F0.Pos = v3{-1, 0, 0};
F0.ComPort = ComPort; F0.ComPort = "\\\\.\\COM4";
F0.FlowerTagValue = "left"; F0.FlowerTagValue = "left";
F0.StemChannels = StemChannels; F0.StemChannels = StemChannels;
F0.BloomOuterChannels = BloomOuterChannels; F0.BloomOuterChannels = BloomOuterChannels;
F0.BloomInnerChannels = BloomInnerChannels; F0.BloomInnerChannels = BloomInnerChannels;
BuildFlower(&OutputBuffer, F0); BuildFlower(&OutputBuffer, F0);
#if 1
flower_desc F1 = {}; flower_desc F1 = {};
F1.Pos = v3{0, 0, 0}; F1.Pos = v3{0, 0, 0};
F1.ComPort = "\\\\.\\COM6"; F1.ComPort = "\\\\.\\COM5";
F1.FlowerTagValue = "center"; F1.FlowerTagValue = "center";
F1.StemChannels = StemChannels; F1.StemChannels = StemChannels;
F1.BloomInnerChannels = BloomInnerChannels; F1.BloomInnerChannels = BloomInnerChannels;
F1.BloomOuterChannels = BloomOuterChannels; F1.BloomOuterChannels = BloomOuterChannels;
BuildFlower(&OutputBuffer, F1); BuildFlower(&OutputBuffer, F1);
#endif
/* flower_desc F2 = {};
flower_desc F2 = {}; F2.Pos = v3{1, 0, 0};
F2.Pos = v3{1, 0, 0}; F2.ComPort = "\\\\.\\COM6";
F2.FlowerTagValue = "right"; F2.FlowerTagValue = "right";
F2.StemChannels = StemChannels; F2.StemChannels = StemChannels;
F2.BloomInnerChannels = BloomInnerChannels; F2.BloomInnerChannels = BloomInnerChannels;
F2.BloomOuterChannels = BloomOuterChannels; F2.BloomOuterChannels = BloomOuterChannels;
BuildFlower(&OutputBuffer, F2); BuildFlower(&OutputBuffer, F2);
*/
printf("%.*s\n", (u32)OutputBuffer.Length, OutputBuffer.Str); printf("%.*s\n", (u32)OutputBuffer.Length, OutputBuffer.Str);