#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);
class TFTArtShow {
private:
Adafruit_ILI9341& display;
public:
TFTArtShow(Adafruit_ILI9341& tft) : display(tft) {}
void begin() {
display.begin();
display.setRotation(3);
display.fillScreen(ILI9341_BLACK);
}
void run() {
drawRainbowBackground();
drawShapes();
drawAttractiveDesign();
}
void drawShapes() {
drawCircle();
drawTriangle();
drawRectangle();
drawPolygon(5, 100, ILI9341_YELLOW); // Pentagon
drawPolygon(6, 100, ILI9341_CYAN); // Hexagon
drawStar();
drawEllipse();
drawPolygon(8, 100, ILI9341_PURPLE); // Octagon
}
void drawCircle() {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
for (int r = 100; r > 0; r -= 10) {
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
display.drawCircle(x, y, r, ILI9341_RED);
delay(500);
}
}
void drawTriangle() {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
for (int size = 100; size > 0; size -= 10) {
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
int h = size / 2;
display.drawTriangle(x, y - h, x - h, y + h, x + h, y + h, ILI9341_GREEN);
delay(500);
}
}
void drawRectangle() {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
for (int s = 100; s > 0; s -= 10) {
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
display.drawRect(x - s/2, y - s/2, s, s, ILI9341_BLUE);
delay(500);
}
}
void drawStar() {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
for (int s = 100; s > 0; s -= 10) {
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
int r = s / 2;
for (int i = 0; i < 5; i++) {
float a1 = i * 72 * PI / 180;
float a2 = (i * 72 + 144) * PI / 180;
display.drawLine(
x + r * cos(a1), y - r * sin(a1),
x + r * cos(a2), y - r * sin(a2),
ILI9341_MAGENTA
);
}
delay(500);
}
}
void drawEllipse() {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
for (int s = 100; s > 0; s -= 10) {
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
int a = s / 2, b = s / 4;
for (int d = 0; d < 360; d++) {
float rad = d * PI / 180;
int px = x + a * cos(rad);
int py = y + b * sin(rad);
display.drawPixel(px, py, ILI9341_ORANGE);
}
delay(500);
}
}
void drawPolygon(int sides, int size, uint16_t color) {
int x = TFT_WIDTH / 2, y = TFT_HEIGHT / 2;
float angleStep = 2 * PI / sides;
int prevX = x + size * cos(0);
int prevY = y - size * sin(0);
for (int i = 1; i <= sides; i++) {
float angle = i * angleStep;
int newX = x + size * cos(angle);
int newY = y - size * sin(angle);
display.drawLine(prevX, prevY, newX, newY, color);
prevX = newX; prevY = newY;
}
delay(500);
}
void drawAttractiveDesign() {
for (int i = 0; i < 35; i++) {
uint16_t c = display.color565(random(255), random(255), random(255));
display.drawCircle(TFT_WIDTH/2, TFT_HEIGHT/2, 100, c);
delay(100);
display.fillScreen(ILI9341_BLACK);
drawRainbowBackground();
}
display.setCursor(TFT_WIDTH / 2 - 60, TFT_HEIGHT - 25);
display.setTextColor(ILI9341_WHITE);
display.setTextSize(2);
display.print("अरविंद द्वारे"); // “By Arvind” in Marathi
}
void drawRainbowBackground() {
for (int x = 0; x < TFT_WIDTH; x++) {
float hue = (float)x / TFT_WIDTH;
uint16_t color = HSVtoRGB(hue, 1.0, 1.0);
display.drawLine(x, 0, x, TFT_HEIGHT, color);
}
}
uint16_t HSVtoRGB(float h, float s, float v) {
int i = int(h * 6);
float f = h * 6 - i;
float p = v * (1 - s);
float q = v * (1 - f * s);
float t = v * (1 - (1 - f) * s);
float r, g, b;
switch (i % 6) {
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
return display.color565(r * 255, g * 255, b * 255);
}
};
TFTArtShow artShow(tft);
void setup() {
artShow.begin();
}
void loop() {
artShow.run();
}