// ESP32-S3 + ILI9341 Extraordinary Geometry Demo (C++)
// Requires: Adafruit_GFX.h, Adafruit_ILI9341.h
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// Pin mapping (adjust as needed)
#define TFT_DC 10
#define TFT_CS 11
#define TFT_RST 14
#define TFT_CLK 13
#define TFT_MOSI 12
#define TFT_LED 17
#define TFT_MISO 15
Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
int W, H;
// --- Extraordinary Geometrical Patterns ---
void rotatingPolygon(int sides=6, int radius=80, int steps=60) {
int cx = W/2, cy = H/2;
for (int angle=0; angle<360; angle+=steps) {
display.fillScreen(ILI9341_BLACK);
int x[20], y[20];
for (int i=0; i<sides; i++) {
float theta = 2*M_PI*i/sides + radians(angle);
x[i] = cx + radius*cos(theta);
y[i] = cy + radius*sin(theta);
}
for (int i=0; i<sides; i++) {
int x1=x[i], y1=y[i];
int x2=x[(i+1)%sides], y2=y[(i+1)%sides];
uint16_t color = display.color565((i*40)%255, (i*80)%255, (i*120)%255);
display.drawLine(x1,y1,x2,y2,color);
}
delay(100);
}
}
void sineWavePattern() {
display.fillScreen(ILI9341_BLACK);
for (int x=0; x<W; x++) {
int y = H/2 + 60*sin(x/20.0);
uint16_t color = display.color565((x*2)%255, (y*3)%255, (x*y)%255);
display.drawPixel(x,y,color);
}
delay(1000);
}
void spiralPattern(int turns=20) {
display.fillScreen(ILI9341_BLACK);
int cx=W/2, cy=H/2;
for (int t=1; t<turns*360; t+=5) {
float r = 2*t/10.0;
int x = cx + r*cos(radians(t));
int y = cy + r*sin(radians(t));
uint16_t color = display.color565((t*3)%255, (t*5)%255, (t*7)%255);
display.drawPixel(x,y,color);
}
delay(1000);
}
void fractalTree(int x, int y, float angle, int depth, float length) {
if (depth==0) return;
int x2 = x + length*cos(radians(angle));
int y2 = y - length*sin(radians(angle));
uint16_t color = display.color565((depth*40)%255, (depth*80)%255, (depth*120)%255);
display.drawLine(x,y,x2,y2,color);
fractalTree(x2,y2,angle-20,depth-1,length*0.7);
fractalTree(x2,y2,angle+20,depth-1,length*0.7);
}
void fractalTreePattern() {
display.fillScreen(ILI9341_BLACK);
fractalTree(W/2,H-20,-90,8,60);
delay(2000);
}
void lissajousPattern(int a=3, int b=4, float delta=M_PI/2) {
display.fillScreen(ILI9341_BLACK);
int cx=W/2, cy=H/2;
for (int t=0; t<1000; t+=2) {
int x = cx + 100*sin(a*t/100.0 + delta);
int y = cy + 100*sin(b*t/100.0);
uint16_t color = display.color565((t*3)%255, (t*5)%255, (t*7)%255);
display.drawPixel(x,y,color);
}
delay(2000);
}
// --- Setup & Loop ---
void setup() {
display.begin();
display.setRotation(1); // adjust orientation
W = display.width();
H = display.height();
}
void loop() {
rotatingPolygon(5);
rotatingPolygon(7);
sineWavePattern();
spiralPattern();
fractalTreePattern();
lissajousPattern();
}