88 lines
1.9 KiB
C++
88 lines
1.9 KiB
C++
#include "fx_shootingstar.h"
|
|
#include "effect.h"
|
|
|
|
FX_ShootingStar::FX_ShootingStar(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height)
|
|
{
|
|
_numpixels=numpixels;
|
|
_strip=strip;
|
|
_starttime=millis();
|
|
_brightness=0;
|
|
_duration=random(200,3000);
|
|
_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()
|
|
{
|
|
}
|
|
|
|
void FX_ShootingStar::updateRoutine(float updatedelayms)
|
|
{
|
|
|
|
}
|
|
|
|
void FX_ShootingStar::updateGraphics()
|
|
{
|
|
#define STARTFLASHHEIGHT 100
|
|
#define BRIGHTFLASHHEIGHT 150
|
|
for(int i=0;i<_numpixels;i++){
|
|
if (_height[i]>=STARTFLASHHEIGHT){
|
|
uint8_t heightbrightness=map(_height[i],STARTFLASHHEIGHT,BRIGHTFLASHHEIGHT,0,255);
|
|
|
|
uint8_t _r = 1 >> 16;
|
|
uint8_t _g = 1 >> 8;
|
|
uint8_t _b = 1;
|
|
|
|
_r*=_brightness/255.0;
|
|
_g*=_brightness/255.0;
|
|
_b*=_brightness/255.0;
|
|
|
|
_r*=heightbrightness/255.0;
|
|
_g*=heightbrightness/255.0;
|
|
_b*=heightbrightness/255.0;
|
|
|
|
|
|
uint32_t _pxcolor=_strip->getPixelColor(i); //get current color of that pixel
|
|
uint8_t _pxr = _pxcolor >> 16;
|
|
uint8_t _pxg = _pxcolor >> 8;
|
|
uint8_t _pxb = _pxcolor;
|
|
uint16_t _tmpr=_pxr+_r; //add colors
|
|
uint16_t _tmpg=_pxg+_g;
|
|
uint16_t _tmpb=_pxb+_b;
|
|
_tmpr=constrain(_tmpr,0,255);
|
|
_tmpg=constrain(_tmpr,0,255);
|
|
_tmpb=constrain(_tmpr,0,255);
|
|
|
|
_strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
bool FX_ShootingStar::active()
|
|
{
|
|
/*
|
|
if (millis()-_starttime>_flashtime){
|
|
return false;
|
|
}*/
|
|
return true;
|
|
}
|
|
|