PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Leaves.h 2.3KB

3 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef LEAVES_H__
  2. #define LEAVES_H__
  3. #include <Arduino.h>
  4. #include <math.h>
  5. #include "ILI9341_t3.h"
  6. #include "BaseAnimation.h"
  7. const uint_fast8_t LV_SIZE = 5;
  8. const float LV_SPREAD_RADIUS = 100.0f;
  9. const float LV_ITERS = 2;
  10. const float LV_SPEED = 5.2;
  11. const uint_fast16_t LV_RED = 0xf800;
  12. const uint_fast16_t FADE_RED = 0x1800;
  13. class Leaves : public BaseAnimation {
  14. public:
  15. Leaves() : BaseAnimation() {};
  16. void init( ILI9341_t3 tft );
  17. uint_fast16_t bgColor( void );
  18. String title();
  19. void perFrame( ILI9341_t3 tft, FrameParams frameParams );
  20. private:
  21. void _drawLeaves( ILI9341_t3 tft, boolean doErase, uint_fast8_t iter, float radius, float spin, float x, float y, uint_fast16_t solidColor, uint_fast16_t outlineColor );
  22. float _phase = 0;
  23. uint_fast16_t _bgColor;
  24. };
  25. void Leaves::init( ILI9341_t3 tft ) {
  26. _bgColor = 0x780f;
  27. }
  28. uint_fast16_t Leaves::bgColor(){
  29. return _bgColor;
  30. }
  31. String Leaves::title() {
  32. return "Leaves";
  33. }
  34. void Leaves::_drawLeaves( ILI9341_t3 tft, boolean doErase, uint_fast8_t iter, float radius, float spin, float x, float y, uint_fast16_t solidColor, uint_fast16_t outlineColor ) {
  35. float radius_2 = radius * 0.5;
  36. float angle = M_PI + (spin * (iter+0.7));
  37. for( uint_fast8_t i=0; i<3; i++ ) {
  38. if( iter==0 ) {
  39. tft.drawCircle( x + cos(angle)*radius, y + sin(angle)*radius, LV_SIZE+2, outlineColor );
  40. tft.drawCircle( x + cos(angle)*radius, y + sin(angle)*radius, LV_SIZE+1, outlineColor );
  41. tft.fillCircle( x + cos(angle)*radius, y + sin(angle)*radius, LV_SIZE, solidColor );
  42. } else {
  43. _drawLeaves( tft, doErase, iter-1, radius_2, angle + i*0.2, x + cos(angle)*radius, y + sin(angle)*radius, solidColor, outlineColor );
  44. }
  45. angle += M_PI * (2.0/7.0);
  46. }
  47. }
  48. void Leaves::perFrame( ILI9341_t3 tft, FrameParams frameParams ) {
  49. uint_fast16_t w = tft.width();
  50. uint_fast16_t h = tft.height();
  51. // fillRect: flickers pretty bad
  52. //tft.fillRect( 0, 0, w, h, LV_RED );
  53. float amp_f = frameParams.audioMean; // range [0..1]
  54. _phase += (amp_f*amp_f) * LV_SPEED;
  55. uint_fast8_t bright = (frameParams.audioPeak >> 1); // 0..512 -> 0..255
  56. uint_fast16_t solidColor = tft.color565( 0xff, bright, bright ); // red
  57. uint_fast16_t outlineColor = tft.color565( bright, bright, bright ); // grey
  58. _drawLeaves( tft, false, LV_ITERS, LV_SPREAD_RADIUS, _phase, w/2, h/2, solidColor, outlineColor );
  59. }
  60. #endif