#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft(10, 9);
uint16_t brightnessAdjust(uint16_t color, int brightness) {
uint8_t r = (color >> 11) & 0x1f;
uint8_t g = (color >> 5) & 0x3f;
uint8_t b = (color & 0x1f);
if(brightness <= 100) {
r = (r * brightness)/100;
g = (g * brightness)/100;
b = (b * brightness)/100;
} else {
r += 0x1f * (brightness-100)/100;
g += 0x3f * (brightness-100)/100;
b += 0x1f * (brightness-100)/100;
}
if(r >= 0x1f) r = 0x1f;
if(g >= 0x3f) g = 0x3f;
if(b >= 0x1f) b = 0x1f;
return (r << 11) | (g << 5) | b;
}
void drawCube(int x, int y, uint16_t color) {
tft.fillTriangle(x,y+20, x+40,y, x+2*40,y+20, color);
tft.fillTriangle(x,y+20, x+40,y+2*20, x+2*40,y+20, color);
tft.fillTriangle(x,y+20, x+40,y+2*20, x+40,y+2*20+40, brightnessAdjust(color, 75));
tft.fillTriangle(x,y+20, x,y+20+40, x+40,y+2*20+40, brightnessAdjust(color, 75));
tft.fillTriangle(x+2*40,y+20, x+40,y+2*20, x+40,y+2*20+40, brightnessAdjust(color, 135));
tft.fillTriangle(x+2*40,y+20, x+2*40,y+20+40, x+40,y+2*20+40, brightnessAdjust(color, 135));
}
void drawCurve(int x0, int y0, int h, int w, uint16_t color) {
int a=40, b=40;
for(int i=0; i<w; i++) {
int y = y0 + sqrt(sq(b) - sq((b*i)/a));
tft.drawLine(x0+i,y, x0+i,y+h, brightnessAdjust(color, 40+3*i));
}
}
void drawCurtain(int x0, int y0, int h, int w, uint16_t color1, uint16_t color2) {
for(int i=0; i<w; i++) {
int brightness = 100-30*sin(0.08*i);
int y = -10*sin(0.08*i);
tft.drawLine(x0+i,y+y0, x0+i, y+y0+h, brightnessAdjust(color1, brightness));
}
for(int j=0; j<h; j+=25) {
for(int i=0; i<w; i++) {
int brightness = 100-30*sin(0.08*i);
int y = -10*sin(0.08*i);
tft.drawLine(x0+i,y+j+y0, x0+i, y+j+y0+2, brightnessAdjust(color2, brightness));
}
}
}
void setup() {
tft.begin();
tft.fillScreen(0xffff);
}
void loop() {
drawCube(20, 40, 0xff0f);
drawCurve(40,150, 60, 40, 0x7ff);
drawCurtain(120, 60, 100, 110, 0xf809, 0xffe0);
delay(5000);
while(1);
}