#include <TFT_eSPI.h>
#include <SPI.h> // this is needed for display
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
#include <QList.h>
#include <ArxSmartPtr.h>
float PIE = 3.14;
#include "randomColor.h";
#include "shape.h";
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define ILI9341_RED TFT_RED
#define ILI9341_YELLOW TFT_YELLOW
#define ILI9341_GREEN TFT_GREEN
#define ILI9341_CYAN TFT_CYAN
#define ILI9341_BLUE TFT_BLUE
#define ILI9341_MAGENTA TFT_MAGENTA
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
int period = 1000;
unsigned long time_now = 0;
class ellipse : public shape {
public:
ellipse(float xloc, float yloc, int size, int color, float speed, float direction): shape(xloc, yloc, size, color, speed, direction) {}
void draw()override {
tft.drawEllipse(xloc - size - 2, yloc - size - 2, size + 4, size * 2 + 4, TFT_BLACK);
tft.drawEllipse(xloc - size - 1, yloc - size - 1, size + 2, size * 2 + 2, TFT_BLACK);
tft.fillEllipse(xloc - size, yloc - size, size, size * 2, color);
}
};
class square : public shape {
public:
square(float xloc, float yloc, int size, int color, float speed, float direction): shape(xloc, yloc, size, color, speed, direction) {}
void draw()override {
tft.drawRect(xloc - size - 2, yloc - size - 2, size * 2 + 4, size * 2 + 4, TFT_BLACK);
tft.drawRect(xloc - size - 1, yloc - size - 1, size * 2 + 2, size * 2 + 2, TFT_BLACK);
tft.fillRect(xloc - size, yloc - size, size * 2, size * 2, color);
}
};
class circle : public shape {
public:
circle(float xloc, float yloc, int size, int color, float speed, float direction): shape(xloc, yloc, size, color, speed, direction) {}
void draw()override {
tft.drawCircle(xloc, yloc, size + 1, TFT_BLACK);
tft.drawCircle(xloc, yloc, size + 2, TFT_BLACK);
tft.fillCircle(xloc, yloc, size + 2, TFT_BLACK);
tft.fillCircle(xloc, yloc, size, color);
}
};
class triangle: public shape {
public:
triangle(float xloc, float yloc, int size, int color, float speed, float direction): shape(xloc, yloc, size, color, speed, direction) {}
void draw() override {
tft.drawTriangle(xloc + (size +1) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)), yloc + (size+1) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size +1) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)), yloc + (size+1) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size +1) * cos((direction * 3.1415 / 180)), yloc + (size+1) * sin((direction * 3.1415 / 180)),
TFT_BLACK);
tft.drawTriangle(xloc + (size +2) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)), yloc + (size+2) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size +2) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)), yloc + (size+2) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size +2) * cos((direction * 3.1415 / 180)), yloc + (size+2) * sin((direction * 3.1415 / 180)),
TFT_BLACK);
tft.drawTriangle(xloc + (size +3) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),yloc + (size+3) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size +3) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),yloc + (size+3) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size +3) * cos((direction * 3.1415 / 180)), yloc + (size+3) * sin((direction * 3.1415 / 180)),
TFT_BLACK);
tft.fillTriangle(xloc + (size +3) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),yloc + (size+3) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size +3) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),yloc + (size+3) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size +3) * cos((direction * 3.1415 / 180)), yloc + (size+3) * sin((direction * 3.1415 / 180)),
TFT_BLACK);
tft.fillCircle(xloc, yloc, size + 3, TFT_BLACK);
tft.drawTriangle(xloc + (size) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)), yloc + (size) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)), yloc + (size) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size) * cos((direction * 3.1415 / 180)), yloc + (size) * sin((direction * 3.1415 / 180)),
color);
tft.fillTriangle(xloc + (size) * cos((direction * 3.1415 / 180) + (2 * 3.1415 / 3)), yloc + (size) * sin((direction * 3.1415 / 180) + (2 * 3.1415 / 3)),
xloc + (size) * cos((direction * 3.1415 / 180) + (4 * 3.1415 / 3)), yloc + (size) * sin((direction * 3.1415 / 180) + (4 * 3.1415 / 3)),
xloc + (size) * cos((direction * 3.1415 / 180)), yloc + (size) * sin((direction * 3.1415 / 180)),
color);
}
};
QList<std::shared_ptr<shape>> shapeList;
void setup() {
pinMode(27, INPUT);
tft.init();
tft.fillScreen(TFT_BLACK);
tft.setRotation(1);
// for (int i = 0; i < 2; i++) {
// std::shared_ptr<shape> newPointerObject(new triangle(random(5, 315), random(5, 235), 10, randomColor(), 1, random(0, 360)));
// shapeList.push_back(newPointerObject);
// }
// for (int i = 0; i < 2; i++) {
// std::shared_ptr<shape> newPointerObject(new square(random(5, 315), random(5, 235), 10, randomColor(), 1, random(0, 360)));
// shapeList.push_back(newPointerObject);
// }
// for (int i = 0; i < 2; i++) {
// std::shared_ptr<shape> newPointerObject(new circle(random(5, 315), random(5, 235), 10, randomColor(), 1, random(0, 360)));
// shapeList.push_back(newPointerObject);
// }
for (int i = 0; i < 2; i++) {
std::shared_ptr<shape> newPointerObject(new ellipse(random(5, 315), random(5, 235), 10, randomColor(), 1, random(0, 360)));
shapeList.push_back(newPointerObject);
}
}
int fps = 0;
void loop() {
fps++;
if (millis() >= time_now + period) {
time_now += period;
tft.drawString("fps: " + String(fps) + " ", 0, 0, 2);
fps = 0;
}
if (digitalRead(27) == HIGH) {
//shapeList.push_back(b);
}
for (int i = 0; i < shapeList.size(); i++) {
shapeList.at(i)->run();
shapeList.at(i)->checkCollision(shapeList, i); //i indicates which shape on the list is its self
}
}