minor bug fixes and a new animation

This commit is contained in:
2024-08-26 18:49:24 -04:00
parent 35a94f7b5a
commit 5237de0539
4 changed files with 251 additions and 6 deletions

221
lib/Animator/Animation.h Normal file
View File

@@ -0,0 +1,221 @@
#pragma once
#include "AnimationTypes.h"
#include "Vector3D.h"
#include "Animator.h"
using namespace ANIMATION_TYPES;
namespace AnimationHelpers{
V3D<uint8_t> red{255,0,0};
V3D<uint8_t> green{0,255,0};
V3D<uint8_t> blue{0,0,255};
V3D<uint8_t> cyan{0,255,255};
V3D<uint8_t> magenta{255,0,255};
Cell CreateCell(float x_percent, float y_percent, float z_percent, V3D<uint8_t> &color){
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
Cell cell{
.position = V3D<uint32_t>{
static_cast<uint32_t>(continuousMaxValue*x_percent),
static_cast<uint32_t>(continuousMaxValue*y_percent),
static_cast<uint32_t>(continuousMaxValue*z_percent)
},
.color = color
};
return cell;
}
}
namespace RotatingCubes{
using namespace AnimationHelpers;
AnimationFrame frame1{
.frame = {
CreateCell(0,0,0,red),
CreateCell(1,0.5,0,green),
CreateCell(0,1,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1000)
};
AnimationFrame frame2{
.frame = {
CreateCell(0,0.5,0,red),
CreateCell(1,0,0,green),
CreateCell(0.5,1,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(500)
};
AnimationFrame frame3{
.frame = {
CreateCell(0,1,0,red),
CreateCell(0.5,0,0,green),
CreateCell(1,1,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1000)
};
AnimationFrame frame4{
.frame = {
CreateCell(0.5,1,0,red),
CreateCell(0,0,0,green),
CreateCell(1,0.5,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(500)
};
AnimationFrame frame5{
.frame = {
CreateCell(1,1,0,red),
CreateCell(0,0.5,0,green),
CreateCell(1,0,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1000)
};
AnimationFrame frame6{
.frame = {
CreateCell(1,0.5,0,red),
CreateCell(0,1,0,green),
CreateCell(0.5,0,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(500)
};
AnimationFrame frame7{
.frame = {
CreateCell(1,0,0,red),
CreateCell(0.5,1,0,green),
CreateCell(0,0,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1000)
};
AnimationFrame frame8{
.frame = {
CreateCell(0.5,0,0,red),
CreateCell(1,1,0,green),
CreateCell(0,0.5,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(500)
};
AnimationFrame frame9{
.frame = {
CreateCell(0,0,0,red),
CreateCell(1,0.5,0,green),
CreateCell(0,1,0,blue)
},
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1)
};
std::vector<AnimationFrame> rotating{
frame1, // 0
frame2, // 1
frame3, // 2
frame4, // 3
frame5, // 4
frame6, // 5
frame7, // 6
frame8, // 7
frame9, // 8
};
}
namespace RisingCubes{
using namespace AnimationHelpers;
AnimationFrame frame1{
.frame = {
CreateCell(0,0,0,cyan),
CreateCell(0,1,0.5,green),
CreateCell(1,0,1,blue),
CreateCell(0.5,0.5,0.5,red),
CreateCell(1,1,0,magenta)
},
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(800)
};
AnimationFrame frame2{
.frame = {
CreateCell(0,0,0.5,cyan),
CreateCell(0,1,1,green),
CreateCell(1,0,0.5,blue),
CreateCell(0.5,0.5,0,red),
CreateCell(1,1,0.5,magenta)
},
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(800)
};
AnimationFrame frame3{
.frame = {
CreateCell(0,0,1,cyan),
CreateCell(0,1,0.5,green),
CreateCell(1,0,0,blue),
CreateCell(0.5,0.5,0.5,red),
CreateCell(1,1,1,magenta)
},
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(800)
};
AnimationFrame frame4{
.frame = {
CreateCell(0,0,0.5,cyan),
CreateCell(0,1,0,green),
CreateCell(1,0,0.5,blue),
CreateCell(0.5,0.5,1,red),
CreateCell(1,1,0.5,magenta)
},
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(800)
};
AnimationFrame frame5{
.frame = {
CreateCell(0,0,0,cyan),
CreateCell(0,1,0.5,green),
CreateCell(1,0,1,blue),
CreateCell(0.5,0.5,0.5,red),
CreateCell(1,1,0,magenta)
},
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
.frameInterpolation = FrameInterpolation::FADE,
.delay = std::chrono::milliseconds(1)
};
std::vector<AnimationFrame> rising{
frame1, // 0
frame2, // 1
frame3, // 2
frame4, // 3
frame5
};
}

View File

@@ -121,7 +121,7 @@ void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
stringBuffer += String(linearizedBoard[0]);
for(uint32_t i = 0; i < BOARD_DIMS.x * BOARD_DIMS.y; i++){
for(uint32_t i = 1; i < BOARD_DIMS.x * BOARD_DIMS.y; i++){
stringBuffer += "," + String(linearizedBoard[i]);
}
}

View File

@@ -68,6 +68,7 @@ class BoardManager{
void Board2StackString(String& messageBuffer);
void FillColor(const V3D<uint32_t> &color){this->board.FillColor(color);}
void PrintColorState(){this->board.PrintEntireBoard();}
private:
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
@@ -167,7 +168,7 @@ void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D<uint32_t> &column, cons
uint32_t sliceLength{this->board.SliceBoard(column, slicedBoard)};
uint32_t maxIndex{std::min(numColors, columnHeight)};
for(uint32_t i = 0; i < columnHeight; i++){
for(uint32_t i = 0; i < maxIndex; i++){
slicedBoard[i]->color = color[i];
}
}