acidportal

- 😈 Worlds smallest Evil Portal on a LilyGo T-QT
git clone git://git.acid.vegas/acidportal.git
Log | Files | Refs | Archive | README | LICENSE

TFT_Spiro.ino (2190B)

      1 // Spiro
      2 // Rainbow patern generator
      3 
      4 #include <TFT_eSPI.h> // Hardware-specific library
      5 #include <SPI.h>
      6 
      7 TFT_eSPI tft = TFT_eSPI();       // Invoke custom library
      8 
      9 #define DEG2RAD 0.0174532925 // Convert angles in degrees to radians
     10 
     11 unsigned long runTime = 0;
     12 
     13 float sx = 0, sy = 0;
     14 uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
     15 
     16 void setup()
     17 {
     18   //randomSeed(analogRead(A0));
     19 
     20   // Setup the LCD
     21   tft.init();
     22   tft.setRotation(3);
     23 }
     24 
     25 void loop()
     26 {
     27   runTime = millis();
     28 
     29   tft.fillScreen(TFT_BLACK);
     30   int n = random(2, 23), r = random(20, 100), colour = 0; //rainbow();
     31 
     32   for (long i = 0; i < (360 * n); i++) {
     33     sx = cos((i / n - 90) * DEG2RAD);
     34     sy = sin((i / n - 90) * DEG2RAD);
     35     x0 = sx * (120 - r) + 159;
     36     yy0 = sy * (120 - r) + 119;
     37 
     38 
     39     sy = cos(((i % 360) - 90) * DEG2RAD);
     40     sx = sin(((i % 360) - 90) * DEG2RAD);
     41     x1 = sx * r + x0;
     42     yy1 = sy * r + yy0;
     43     tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour);
     44   }
     45   
     46   r = random(20, 100);//r = r / random(2,4);
     47   for (long i = 0; i < (360 * n); i++) {
     48     sx = cos((i / n - 90) * DEG2RAD);
     49     sy = sin((i / n - 90) * DEG2RAD);
     50     x0 = sx * (120 - r) + 159;
     51     yy0 = sy * (120 - r) + 119;
     52 
     53 
     54     sy = cos(((i % 360) - 90) * DEG2RAD);
     55     sx = sin(((i % 360) - 90) * DEG2RAD);
     56     x1 = sx * r + x0;
     57     yy1 = sy * r + yy0;
     58     tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour);
     59   }
     60 
     61 
     62   delay(2000);
     63 }
     64 
     65 unsigned int rainbow(int value)
     66 {
     67   // Value is expected to be in range 0-127
     68   // The value is converted to a spectrum colour from 0 = blue through to red = blue
     69   //int value = random (128);
     70   byte red = 0; // Red is the top 5 bits of a 16 bit colour value
     71   byte green = 0;// Green is the middle 6 bits
     72   byte blue = 0; // Blue is the bottom 5 bits
     73 
     74   byte quadrant = value / 32;
     75 
     76   if (quadrant == 0) {
     77     blue = 31;
     78     green = 2 * (value % 32);
     79     red = 0;
     80   }
     81   if (quadrant == 1) {
     82     blue = 31 - (value % 32);
     83     green = 63;
     84     red = 0;
     85   }
     86   if (quadrant == 2) {
     87     blue = 0;
     88     green = 63;
     89     red = value % 32;
     90   }
     91   if (quadrant == 3) {
     92     blue = 0;
     93     green = 63 - 2 * (value % 32);
     94     red = 31;
     95   }
     96   return (red << 11) + (green << 5) + blue;
     97 }
     98 
     99