85 lines
2.0 KiB
C++
85 lines
2.0 KiB
C++
#include "fx_scanner.h"
|
|
|
|
FX_Scanner::FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor)
|
|
{
|
|
_numpixels=numpixels;
|
|
_pos = startpos;
|
|
_strip=strip;
|
|
_height=height;
|
|
_vel=scannervel;
|
|
_scannercolor=scannercolor;
|
|
}
|
|
|
|
FX_Scanner::FX_Scanner()
|
|
{
|
|
_numpixels=0;
|
|
_pos = -1; //for active false
|
|
_strip=0;
|
|
_height=0;
|
|
_vel=0;
|
|
_scannercolor=0;
|
|
}
|
|
|
|
void FX_Scanner::updateRoutine(float updatedelayms)
|
|
{
|
|
_pos+=_vel*updatedelayms/1000.0;
|
|
}
|
|
|
|
void FX_Scanner::updateGraphics()
|
|
{
|
|
#define FEATHERDISTANCE 3 //in both directions
|
|
for(int i=0;i<_numpixels;i++){
|
|
float heightdistfromlaser=abs(_height[i]-_pos);
|
|
if (heightdistfromlaser<=FEATHERDISTANCE) {
|
|
|
|
uint8_t _r = _scannercolor >> 16;
|
|
uint8_t _g = _scannercolor >> 8;
|
|
uint8_t _b = _scannercolor;
|
|
|
|
float distmult=1.0-(heightdistfromlaser/FEATHERDISTANCE);
|
|
_r*=distmult;
|
|
_g*=distmult;
|
|
_b*=distmult;
|
|
|
|
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;
|
|
if (_tmpr>255){ //clamp
|
|
_tmpr=255;
|
|
}
|
|
if (_tmpg>255){
|
|
_tmpg=255;
|
|
}
|
|
if (_tmpb>255){
|
|
_tmpb=255;
|
|
}
|
|
_strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel
|
|
}
|
|
}
|
|
}
|
|
|
|
bool FX_Scanner::active()
|
|
{
|
|
if (_pos>256 || _pos<0){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
uint32_t FX_Scanner::Wheel(byte WheelPos,float brightness) {
|
|
WheelPos = 255 - WheelPos;
|
|
if(WheelPos < 85) {
|
|
return _strip->Color(255 - WheelPos * 3*brightness, 0, WheelPos * 3*brightness);
|
|
}
|
|
if(WheelPos < 170) {
|
|
WheelPos -= 85;
|
|
return _strip->Color(0, WheelPos * 3*brightness, 255 - WheelPos * 3*brightness);
|
|
}
|
|
WheelPos -= 170;
|
|
return _strip->Color(WheelPos * 3*brightness, 255 - WheelPos * 3*brightness, 0);
|
|
}
|