PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.2KB

  1. #ifndef PLASMA_YELLOW_H__
  2. #define PLASMA_YELLOW_H__
  3. #include <Arduino.h>
  4. #include "ILI9341_t3.h"
  5. #include "MathUtil.h"
  6. #include "BaseAnimation.h"
  7. const float PLASMA_YELLOW_SPEED = 0.02;
  8. const uint_fast8_t PLASMA_YELLOW_DITHER = 8;
  9. const uint_fast16_t PLASMA_YELLOW_MARGIN = 25;
  10. class PlasmaYellow : public BaseAnimation {
  11. public:
  12. PlasmaYellow() : BaseAnimation() {};
  13. void init( ILI9341_t3 tft );
  14. uint_fast16_t bgColor( void );
  15. String title();
  16. void perFrame( ILI9341_t3 tft, FrameParams frameParams );
  17. private:
  18. float _phase = 0;
  19. uint_fast8_t _ditherY = 0;
  20. uint_fast16_t _bgColor;
  21. };
  22. void PlasmaYellow::init( ILI9341_t3 tft ) {
  23. _bgColor = tft.color565( 0xff, 0xff, 0 );
  24. }
  25. uint_fast16_t PlasmaYellow::bgColor(){
  26. return _bgColor;
  27. }
  28. String PlasmaYellow::title() {
  29. return "PlasmaYellow";
  30. }
  31. void PlasmaYellow::perFrame( ILI9341_t3 tft, FrameParams frameParams ) {
  32. int_fast16_t w = (int_fast16_t)tft.width();
  33. int_fast16_t h = (int_fast16_t)tft.height();
  34. _phase += frameParams.timeMult * PLASMA_YELLOW_SPEED;
  35. _ditherY = (_ditherY + 1) % PLASMA_YELLOW_DITHER;
  36. Point16 p0 = (Point16){
  37. (int_fast16_t)(w/2 + (sin(_phase*0.57f)*(w/2-PLASMA_YELLOW_MARGIN) )),
  38. (int_fast16_t)(h/2 + (sin(_phase*0.23f)*(h/2-PLASMA_YELLOW_MARGIN) ))
  39. };
  40. Point16 p1 = (Point16){
  41. (int_fast16_t)(w/2 + (cos(_phase*0.78f)*(w/2-PLASMA_YELLOW_MARGIN) )),
  42. (int_fast16_t)(h/2 + (cos(_phase*0.42f)*(h/2-PLASMA_YELLOW_MARGIN) ))
  43. };
  44. float audioPower = frameParams.audioMean;
  45. for( int_fast16_t x=0; x<w; x+=PLASMA_YELLOW_DITHER ) {
  46. for( int_fast16_t y=_ditherY; y<h; y+=PLASMA_YELLOW_DITHER ) {
  47. Point16 d0 = (Point16){ p0.x - x, p0.y - y };
  48. Point16 d1 = (Point16){ p1.x - x, p1.y - y };
  49. //uint_fast16_t distance = sqrt( d0.x*d0.x + d0.y*d0.y );// * sqrt( d1.x*d1.x + d1.y*d1.y ); // SLOW
  50. //uint_fast16_t distance = abs( d0.x*d0.y ); // pretty good
  51. uint_fast16_t distance = abs( d0.x*d0.y + d1.x*d1.y );
  52. uint_fast8_t bright = lerp8( (uint_fast16_t)(distance >> 5) & 0xff, 0xff, audioPower );
  53. if( bright > 0x7f ) bright = 0xff - bright;
  54. bright <<= 2;
  55. uint_fast16_t color = tft.color565( bright, bright, 0 );
  56. tft.drawFastHLine( x, y, PLASMA_YELLOW_DITHER, color );
  57. }
  58. }
  59. }
  60. #endif