Adding 2 ball track modes

With and without collisions
This commit is contained in:
pjhatch 2020-07-12 08:33:48 -05:00
parent 341d9d1697
commit a20358b61b
3 changed files with 28 additions and 16 deletions

View File

@ -2528,13 +2528,6 @@ typedef struct Ball {
float impactVelocity;
float height;
} ball;
// modified for balltrack mode
typedef struct Ballt {
unsigned long lastBounceUpdate;
float mass; // could fix this to be = 1. if memory is an issue
float velocity;
float height;
} ballt;
/*
* Bouncing Balls Effect
*/
@ -2594,7 +2587,15 @@ uint16_t WS2812FX::mode_bouncing_balls(void) {
/*
* bouncing balls on a track track Effect modified from Air Cookie's bouncing balls
*/
uint16_t WS2812FX::mode_balltrack(void) {
// modified for balltrack mode
typedef struct Ballt {
unsigned long lastBounceUpdate;
float mass; // could fix this to be = 1. if memory is an issue
float velocity;
float height;
} ballt;
uint16_t WS2812FX::ball_track(bool collide) {
//allocate segment data
uint16_t maxNumBalls = 16;
uint16_t dataSize = sizeof(ballt) * maxNumBalls;
@ -2641,8 +2642,7 @@ uint16_t WS2812FX::mode_balltrack(void) {
balls[i].height=thisHeight;
}
// check for collisions
bool docol=true;
if(docol){
if(collide){
for(uint8_t j= i+1; j < numBalls; j++){
if(balls[j].velocity != balls[i].velocity) {
// tcollided + balls[j].lastBounceUpdate is acutal time of collision (this keeps precision with long to float conversions)
@ -2683,6 +2683,13 @@ uint16_t WS2812FX::mode_balltrack(void) {
return FRAMETIME;
}
uint16_t WS2812FX::mode_balltrack(void) {
return ball_track(false);
}
uint16_t WS2812FX::mode_balltrack_collide(void) {
return ball_track(true);
}
/*
* Sinelon stolen from FASTLED examples

View File

@ -98,7 +98,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED )
#define MODE_COUNT 113
#define MODE_COUNT 114
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
@ -213,6 +213,7 @@
#define FX_MODE_FLOW 110
#define FX_MODE_CHUNCHUN 111
#define FX_MODE_BALLTRACK 112
#define FX_MODE_BALLTRACK_COLLIDE 113
class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void);
@ -413,6 +414,7 @@ class WS2812FX {
_mode[FX_MODE_FLOW] = &WS2812FX::mode_flow;
_mode[FX_MODE_CHUNCHUN] = &WS2812FX::mode_chunchun;
_mode[FX_MODE_BALLTRACK] = &WS2812FX::mode_balltrack;
_mode[FX_MODE_BALLTRACK_COLLIDE] = &WS2812FX::mode_balltrack_collide;
_brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black);
targetPalette = CloudColors_p;
@ -608,7 +610,8 @@ class WS2812FX {
mode_phased_noise(void),
mode_flow(void),
mode_chunchun(void),
mode_balltrack(void);
mode_balltrack(void),
mode_balltrack_collide(void);
private:
NeoPixelWrapper *bus;
@ -656,7 +659,8 @@ class WS2812FX {
tricolor_chase(uint32_t, uint32_t),
twinklefox_base(bool),
spots_base(uint16_t),
phased_base(uint8_t);
phased_base(uint8_t),
ball_track(bool collide);
CRGB twinklefox_one_twinkle(uint32_t ms, uint8_t salt, bool cat);
CRGB pacifica_one_layer(uint16_t i, CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff);
@ -696,7 +700,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst",
"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow",
"Heartbeat","Pacifica","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise",
"Flow","Chunchun","Ball Track"
"Flow","Chunchun","Ball Track","Ball Track Collide"
])=====";

View File

@ -1,3 +1,4 @@
/*
* WLED Arduino IDE compatibility file.
*