#ifndef PLASMA_CLOUD_H__ #define PLASMA_CLOUD_H__ #include #include "ILI9488_t3.h" #include "MathUtil.h" #include "BaseAnimation.h" const float PLASMA_CLOUD_SPEED = 0.02; const uint_fast16_t PLASMA_CLOUD_MARGIN = 25; const uint_fast8_t PLASMA_CLOUD_LINE_WIDTH = 8; const uint_fast8_t PLASMA_CLOUD_STEP_Y = 4; const float PLASMA_COLOR_CYCLE_SPEED = 0.003; const uint_fast8_t SQRT_TABLE_LENGTH = 255; uint_fast8_t sqrtTable[ SQRT_TABLE_LENGTH ]; uint_fast8_t sqrtBitShift; // Shift distances (integers) this many bits. This will give you a lookup index to get the square root. class PlasmaCloud : public BaseAnimation { public: PlasmaCloud() : BaseAnimation() {}; void init( ILI9488_t3 tft ); uint_fast16_t bgColor( void ); String title(); void perFrame( ILI9488_t3 tft, FrameParams frameParams ); private: float _phase = 0; float _colorCycle = 0; uint_fast8_t _ditherY = 0; uint_fast16_t _bgColor; }; void PlasmaCloud::init( ILI9488_t3 tft ) { _bgColor = tft.color565( 0x77, 0, 0xcc ); float w = (float)tft.width(); float h = (float)tft.height(); float maxScreenDistance = (w*w) + (h*h); uint_fast8_t nextPow2 = ceil( log2f( maxScreenDistance ) ); float maxTableDistance = pow( 2.0f, nextPow2 ); sqrtBitShift = nextPow2 - 8; float sqrtTableMult = (float)0xff / sqrt(maxScreenDistance); for( uint_fast8_t i=0; i> sqrtBitShift; uint_fast8_t lookup1 = (d1.x*d1.x + d1.y*d1.y) >> sqrtBitShift; //uint_fast8_t lookup2 = (d2.x*d2.x + d2.y*d2.y) >> sqrtBitShift; uint_fast8_t bright = (sqrtTable[ lookup0 ] * sqrtTable[ lookup1 ] ) >> 6; bright = (uint_fast16_t)(bright + colorAdd) & 0xff; uint_fast16_t color = tft.color565( ((bright&0xfb)<<2), 0, bright ); tft.drawFastHLine( x, y, PLASMA_CLOUD_LINE_WIDTH, color ); } } _ditherY = (_ditherY + 1) % PLASMA_CLOUD_STEP_Y; } #endif