acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
Draw_Smooth_Circles.ino (2710B)
1 // Example for drawSmoothCircle function. Which draws anti-aliased circles 2 // The circle periphery has a "thickness" of ~3 pixles to minimise the 3 // "braiding" effect present in narrow anti-aliased lines. 4 5 // For thicker or thinner circle outlines use the drawArc function. 6 7 #include <TFT_eSPI.h> // Include the graphics library 8 TFT_eSPI tft = TFT_eSPI(); // Create object "tft" 9 10 // ------------------------------------------------------------------------- 11 // Setup 12 // ------------------------------------------------------------------------- 13 void setup(void) { 14 Serial.begin(115200); 15 tft.init(); 16 tft.fillScreen(TFT_BLACK); 17 } 18 19 // ------------------------------------------------------------------------- 20 // Main loop 21 // ------------------------------------------------------------------------- 22 void loop() 23 { 24 static uint32_t radius = 2; 25 static uint32_t index = 0; 26 27 uint16_t fg_color = rainbow(index); 28 uint16_t bg_color = TFT_BLACK; // This is the background colour used for smoothing (anti-aliasing) 29 30 uint16_t x = tft.width() / 2; // Position of centre of arc 31 uint16_t y = tft.height() / 2; 32 33 tft.drawSmoothCircle(x, y, radius, fg_color, bg_color); 34 35 radius += 11; 36 index += 5; 37 index = index%192; 38 39 if (radius > tft.height()/2) { 40 delay (1000); 41 radius = 2; 42 } 43 } 44 45 46 // ------------------------------------------------------------------------- 47 // Return a 16 bit rainbow colour 48 // ------------------------------------------------------------------------- 49 unsigned int rainbow(byte value) 50 { 51 // If 'value' is in the range 0-159 it is converted to a spectrum colour 52 // from 0 = red through to 127 = blue to 159 = violet 53 // Extending the range to 0-191 adds a further violet to red band 54 55 value = value%192; 56 57 byte red = 0; // Red is the top 5 bits of a 16 bit colour value 58 byte green = 0; // Green is the middle 6 bits, but only top 5 bits used here 59 byte blue = 0; // Blue is the bottom 5 bits 60 61 byte sector = value >> 5; 62 byte amplit = value & 0x1F; 63 64 switch (sector) 65 { 66 case 0: 67 red = 0x1F; 68 green = amplit; // Green ramps up 69 blue = 0; 70 break; 71 case 1: 72 red = 0x1F - amplit; // Red ramps down 73 green = 0x1F; 74 blue = 0; 75 break; 76 case 2: 77 red = 0; 78 green = 0x1F; 79 blue = amplit; // Blue ramps up 80 break; 81 case 3: 82 red = 0; 83 green = 0x1F - amplit; // Green ramps down 84 blue = 0x1F; 85 break; 86 case 4: 87 red = amplit; // Red ramps up 88 green = 0; 89 blue = 0x1F; 90 break; 91 case 5: 92 red = 0x1F; 93 green = 0; 94 blue = 0x1F - amplit; // Blue ramps down 95 break; 96 } 97 return red << 11 | green << 6 | blue; 98 }