Editing patterns

This commit is contained in:
PS 2020-11-14 22:08:13 -08:00
parent e51188398d
commit 31ee768032
3 changed files with 134 additions and 4 deletions

View File

@ -145,9 +145,11 @@ INITIALIZE_APPLICATION(InitializeApplication)
Animation_AddLayer(&Anim, MakeString("Color Layer"), BlendMode_Multiply, &State->AnimationSystem); Animation_AddLayer(&Anim, MakeString("Color Layer"), BlendMode_Multiply, &State->AnimationSystem);
Animation_AddLayer(&Anim, MakeString("Sparkles"), BlendMode_Add, &State->AnimationSystem); Animation_AddLayer(&Anim, MakeString("Sparkles"), BlendMode_Add, &State->AnimationSystem);
Animation_AddBlock(&Anim, 22, 123, 2, 0); Animation_AddBlock(&Anim, 0, Anim.PlayableRange.Max, 4, 0);
AnimationArray_Push(&State->AnimationSystem.Animations, Anim); AnimationArray_Push(&State->AnimationSystem.Animations, Anim);
State->AnimationSystem.TimelineShouldAdvance = true;
} // End Animation Playground } // End Animation Playground

View File

@ -202,15 +202,128 @@ TestPatternThree(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena*
} }
} }
v4 HSVToRGB (v4 In)
{
float Hue = In.x;
while (Hue > 360.0f) { Hue -= 360.0f; }
while (Hue < 0.0f) { Hue += 360.0f; }
float Sat = In.y;
float Value = In.z;
float hh, p, q, t, ff;
long i;
v4 Result = {};
Result.a = In.a;
if(Sat <= 0.0f) { // < is bogus, just shuts up warnings
Result.r = Value;
Result.g = Value;
Result.b = Value;
return Result;
}
hh = Hue;
if(hh >= 360.0f) hh = 0.0f;
hh /= 60.0f;
i = (long)hh;
ff = hh - i;
p = Value * (1.0f - Sat);
q = Value * (1.0f - (Sat * ff));
t = Value * (1.0f - (Sat * (1.0f - ff)));
switch(i) {
case 0:
{Result.r = Value;
Result.g = t;
Result.b = p;
}break;
case 1:
{
Result.r = q;
Result.g = Value;
Result.b = p;
}break;
case 2:
{
Result.r = p;
Result.g = Value;
Result.b = t;
}break;
case 3:
{
Result.r = p;
Result.g = q;
Result.b = Value;
}break;
case 4:
{
Result.r = t;
Result.g = p;
Result.b = Value;
}break;
case 5:
default:
{
Result.r = Value;
Result.g = p;
Result.b = q;
}break;
}
return Result;
}
internal void internal void
Pattern_AllGreen(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient) Pattern_AllGreen(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
{ {
#if 1
r32 Height = SinR32(Time) * 25;
r32 CycleLength = 5.0f;
r32 CycleProgress = FractR32(Time / CycleLength);
r32 CycleBlend = (SinR32(Time) * .5f) + .5f;
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++) for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{ {
Leds->Colors[LedIndex].R = 0; v4 Pos = Leds->Positions[LedIndex];
Leds->Colors[LedIndex].B = 255; r32 Dist = Pos.y - Height;
Leds->Colors[LedIndex].G = 255;
v4 HSV = { (ModR32(Dist, 25) / 25) * 360, 1, 1, 1 };
v4 RGB = HSVToRGB(HSV);
u8 R = (u8)(RGB.x * 255);
u8 G = (u8)(RGB.y * 255);
u8 B = (u8)(RGB.z * 255);
Leds->Colors[LedIndex].R = R;
Leds->Colors[LedIndex].G = G;
Leds->Colors[LedIndex].B = B;
} }
#else
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{
u32 I = LedIndex + 1;
Leds->Colors[LedIndex] = {};
if (I % 3 == 0)
{
Leds->Colors[LedIndex].R = 255;
}
else if (I % 3 == 1)
{
Leds->Colors[LedIndex].G = 255;
}
else if (I % 3 == 2)
{
Leds->Colors[LedIndex].B = 255;
}
}
#endif
} }
// END TEMPORARY PATTERNS // END TEMPORARY PATTERNS

View File

@ -441,6 +441,21 @@ SqrtU32(u32 V)
return sqrt(V); return sqrt(V);
} }
internal r32
ModR32(r32 Value, r32 Int)
{
r32 Div = Value / Int;
r32 Fract = Abs(FractR32(Div));
return Int * Fract;
}
internal r64
ModR64(r64 Value, r64 Int)
{
r64 Div = Value / Int;
r64 Fract = Abs(FractR64(Div));
return Int * Fract;
}
internal r32 internal r32
SinR32(r32 Rad) SinR32(r32 Rad)
{ {