start adding shootingstar effect

This commit is contained in:
interfisch 2021-10-16 12:04:37 +02:00
parent c05133d8f8
commit 1a938f1e30
4 changed files with 42 additions and 24 deletions

View File

@ -7,8 +7,26 @@ FX_ShootingStar::FX_ShootingStar(int numpixels,Adafruit_NeoPixel *strip,uint8_t
_strip=strip; _strip=strip;
_starttime=millis(); _starttime=millis();
_brightness=0; _brightness=0;
_flashtime=random(200,3000); _duration=random(200,3000);
_height=height; _height=height;
//find a random pixel
_vel=0;
while (_vel==0)
{
_pos=random(10,numpixels-10); //start with random position
int _postest=0;
while(_vel<=0 && _postest<10) {
_postest++;
_vel = _height[_pos] - _height[_pos+_postest]; //height difference
}
_postest=0;
while(_vel<=0 && _postest>-10) {
_postest--;
_vel = _height[_pos] - _height[_pos+_postest]; //height difference
}
}
} }
FX_ShootingStar::FX_ShootingStar() FX_ShootingStar::FX_ShootingStar()
@ -17,13 +35,7 @@ FX_ShootingStar::FX_ShootingStar()
void FX_ShootingStar::updateRoutine(float updatedelayms) void FX_ShootingStar::updateRoutine(float updatedelayms)
{ {
float negativelikelihood=pow(( (millis()-_starttime)*1.0/_flashtime ),2); // 0=most likely, 1=unlikely
_brightness*=0.2;
if (random(0,negativelikelihood*20)==0){
_brightness=random(100,255);
}
//_brightness=(1.0-pow((255-_brightness)/255.0,4))*255.0;
} }
void FX_ShootingStar::updateGraphics() void FX_ShootingStar::updateGraphics()
@ -66,9 +78,10 @@ void FX_ShootingStar::updateGraphics()
bool FX_ShootingStar::active() bool FX_ShootingStar::active()
{ {
/*
if (millis()-_starttime>_flashtime){ if (millis()-_starttime>_flashtime){
return false; return false;
} }*/
return true; return true;
} }

View File

@ -18,8 +18,10 @@ class FX_ShootingStar : public Effect
Adafruit_NeoPixel *_strip; Adafruit_NeoPixel *_strip;
long _starttime; long _starttime;
uint8_t _brightness; uint8_t _brightness;
long _flashtime; long _duration;
uint8_t *_height; uint8_t *_height;
int _pos;
float _vel;
}; };
#endif #endif

View File

@ -15,7 +15,7 @@
#include "effect.h" #include "effect.h"
#include "fx_scanner.h" #include "fx_scanner.h"
#include "fx_flash.h" #include "fx_flash.h"
#include "fx_stars.h" //#include "fx_shootingstar.h"
void resetHeightmap(); void resetHeightmap();
@ -46,17 +46,18 @@ long lastRoutineUpdate=0;
#define ROUTINEUPDATETIME 20 #define ROUTINEUPDATETIME 20
long lastCheckspawn=0; long lastCheckspawn=0;
#define CHECKSPAWNDELAY 2000 //delay in ms to check random spawn #define CHECKSPAWNDELAY 2000 //delay in ms to check random spawn
#define SPAWNCHANCE 40 //1 out of x times wagon will spawn #define SPAWNCHANCE 20 //1 out of x times wagon will spawn
#define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously #define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously
long lastCheckspawnEffect=0; long lastCheckspawnEffect=0;
#define CHECKSPAWNDELAY_EFFECT 10000 //delay in ms to check random effect #define CHECKSPAWNDELAY_EFFECT 5000 //delay in ms to check random effect
#define SPAWNCHANCE_EFFECT_SCANNER 1000 //1 out of x times spawn effect #define SPAWNCHANCE_EFFECT_SCANNER 1000 //1 out of x times spawn effect
#define SPAWNCHANCE_EFFECT_FLASH 4000 //1 out of x times spawn effect #define SPAWNCHANCE_EFFECT_FLASH 1000 //1 out of x times spawn effect
#define SPAWNCHANCE_EFFECT_STARS 100 //1 out of x times spawn effect #define SPAWNCHANCE_EFFECT_SHOOTINGSTAR 100 //1 out of x times spawn effect
#define BRIGHTNESS_RUN 200 //max brightness #define BRIGHTNESS_RUN 200 //max brightness
#define BRIGHTNESS_RUN_MIN 20 //#define BRIGHTNESS_RUN_MIN 20
#define BRIGHTNESS_RUN_MIN 200
#define BRIGHTNESS_DEBUG 150 #define BRIGHTNESS_DEBUG 150
#define LDR_MIN 700 #define LDR_MIN 700
@ -103,6 +104,7 @@ void setup() {
#endif #endif
EEPROM.begin(4096); //set eeprom size, between 4 and 4096 bytes. EEPROM.begin(4096); //set eeprom size, between 4 and 4096 bytes.
strip.begin(); strip.begin();
strip.setBrightness(BRIGHTNESS_RUN); //150 strip.setBrightness(BRIGHTNESS_RUN); //150
@ -275,7 +277,7 @@ void spawnWagon(){
side_startpos=NUMPIXELS+_randomlength; side_startpos=NUMPIXELS+_randomlength;
side_multi=-1; side_multi=-1;
Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,20,5,10), map(_randomlength,3,20, 5,40))/10.0 , 0 , 5.0 , Wheel((uint8_t)random(0,255))); //spawn new wagon Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,20,0,10)/10.0, map(_randomlength,3,20, 5,40))/10.0 , 0 , random(3.0,7.0) , Wheel((uint8_t)random(0,255))); //spawn new wagon
@ -462,10 +464,10 @@ void checkSerial(){
}else if (serialstring.equals("fx_flash")){ }else if (serialstring.equals("fx_flash")){
Serial.println("Effect Flash"); Serial.println("Effect Flash");
effect=new FX_Flash(NUMPIXELS,&strip,height,strip.Color(200,200,200)); effect=new FX_Flash(NUMPIXELS,&strip,height,strip.Color(200,200,200));
}else if (serialstring.equals("fx_stars")){ }/*else if (serialstring.equals("fx_shootingstar")){
Serial.println("Effect Stars"); Serial.println("Effect Shooting Star");
effect=new FX_Stars(NUMPIXELS,&strip,height); effect=new FX_ShootingStar(NUMPIXELS,&strip,height);
} }*/
} }
} }
@ -621,8 +623,8 @@ void loop_achterbahn(){
effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0)); effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0));
}else if (random(0,SPAWNCHANCE_EFFECT_FLASH)==0){ }else if (random(0,SPAWNCHANCE_EFFECT_FLASH)==0){
effect=new FX_Flash(NUMPIXELS,&strip,height,strip.Color(200,200,200)); effect=new FX_Flash(NUMPIXELS,&strip,height,strip.Color(200,200,200));
}/*else if (random(0,SPAWNCHANCE_EFFECT_STARS)==0){ }/*else if (random(0,SPAWNCHANCE_EFFECT_SHOOTINGSTAR)==0){
effect=new FX_Stars(NUMPIXELS,&strip,height); effect=new FX_ShootingStar(NUMPIXELS,&strip,height);
}*/ }*/
} }

View File

@ -81,7 +81,8 @@ void Wagon::updatePhysics(float updatedelayms)
#define CONST_G 9.81 #define CONST_G 9.81
#define PIXELDISTANCE 1.6666667 // 1/60.0 * 100 #define PIXELDISTANCE 1.6666667 // 1/60.0 * 100
#define C_ROLL 0.001 // = Croll https://de.wikipedia.org/wiki/Rollwiderstand 0.001 (zug) #define C_ROLL 0.001 // = Croll https://de.wikipedia.org/wiki/Rollwiderstand 0.001 (zug)
#define AIRRESFIRST 0.018 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) 0.18 //#define AIRRESFIRST 0.018 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) 0.18
#define AIRRESFIRST 0.05 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) 0.18 test
#define AIRRES 0.001 //for slipstream at second wagon #define AIRRES 0.001 //for slipstream at second wagon
#define AIRRESMUL 0.2 //how much of air resistance the next wagon has #define AIRRESMUL 0.2 //how much of air resistance the next wagon has
//http://www.kfz-tech.de/Biblio/Formelsammlung/Luftwiderstand.htm C_w 0.6 //http://www.kfz-tech.de/Biblio/Formelsammlung/Luftwiderstand.htm C_w 0.6