2021-05-05 15:06:32 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-05-12 18:40:37 +01:00
|
|
|
#include "generic_st7789.hpp"
|
2021-04-23 00:44:27 +01:00
|
|
|
|
|
|
|
using namespace pimoroni;
|
|
|
|
|
2022-05-12 18:40:37 +01:00
|
|
|
const int WIDTH = 240;
|
|
|
|
const int HEIGHT = 240;
|
|
|
|
|
|
|
|
ST7789Generic lcd(WIDTH, HEIGHT, false, nullptr, BG_SPI_FRONT);
|
2021-04-23 00:44:27 +01:00
|
|
|
|
2021-05-05 15:06:32 +01:00
|
|
|
int main() {
|
2022-05-12 18:40:37 +01:00
|
|
|
//lcd.configure_display(false);
|
2021-04-23 00:44:27 +01:00
|
|
|
lcd.set_backlight(255);
|
|
|
|
|
2022-05-27 16:52:43 +01:00
|
|
|
// Delete the default palette and allow us to create up to 256 of our own RGB565 colours
|
|
|
|
lcd.set_palette_mode(ST7789Generic::PaletteModeUSER);
|
|
|
|
|
2021-05-05 15:06:32 +01:00
|
|
|
struct pt {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
uint8_t r;
|
|
|
|
float dx;
|
|
|
|
float dy;
|
2022-05-27 16:52:43 +01:00
|
|
|
Pen pen;
|
2021-05-05 15:06:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<pt> shapes;
|
2021-05-06 14:22:18 +01:00
|
|
|
for(int i = 0; i < 100; i++) {
|
2021-05-05 15:06:32 +01:00
|
|
|
pt shape;
|
|
|
|
shape.r = (rand() % 10) + 3;
|
2022-05-12 18:40:37 +01:00
|
|
|
shape.x = rand() % (lcd.bounds.w - (shape.r * 2));
|
|
|
|
shape.y = rand() % (lcd.bounds.h - (shape.r * 2));
|
|
|
|
shape.x += shape.r;
|
|
|
|
shape.y += shape.r;
|
2021-05-06 14:22:18 +01:00
|
|
|
shape.dx = float(rand() % 255) / 64.0f;
|
|
|
|
shape.dy = float(rand() % 255) / 64.0f;
|
2021-05-05 15:06:32 +01:00
|
|
|
shape.pen = lcd.create_pen(rand() % 255, rand() % 255, rand() % 255);
|
|
|
|
shapes.push_back(shape);
|
|
|
|
}
|
2021-04-23 00:44:27 +01:00
|
|
|
|
2022-05-27 16:52:43 +01:00
|
|
|
Pen BG = lcd.create_pen(120, 40, 60);
|
|
|
|
Pen WHITE = lcd.create_pen(255, 255, 255);
|
|
|
|
|
2021-04-23 00:44:27 +01:00
|
|
|
while(true) {
|
2022-05-27 16:52:43 +01:00
|
|
|
lcd.set_pen(BG);
|
2021-04-23 00:44:27 +01:00
|
|
|
lcd.clear();
|
|
|
|
|
2021-05-05 15:06:32 +01:00
|
|
|
for(auto &shape : shapes) {
|
|
|
|
shape.x += shape.dx;
|
|
|
|
shape.y += shape.dy;
|
2022-05-12 18:40:37 +01:00
|
|
|
if(shape.x < shape.r) shape.dx *= -1;
|
|
|
|
if(shape.x >= lcd.bounds.w - shape.r) shape.dx *= -1;
|
|
|
|
if(shape.y < shape.r) shape.dy *= -1;
|
|
|
|
if(shape.y >= lcd.bounds.h - shape.r) shape.dy *= -1;
|
2021-05-05 15:06:32 +01:00
|
|
|
|
|
|
|
lcd.set_pen(shape.pen);
|
|
|
|
lcd.circle(Point(shape.x, shape.y), shape.r);
|
|
|
|
}
|
|
|
|
|
2022-05-27 16:52:43 +01:00
|
|
|
lcd.set_pen(WHITE);
|
2022-05-12 18:40:37 +01:00
|
|
|
lcd.text("Hello World", Point(0, 0), 240);
|
|
|
|
|
2021-05-05 15:06:32 +01:00
|
|
|
// update screen
|
2021-04-23 00:44:27 +01:00
|
|
|
lcd.update();
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:06:32 +01:00
|
|
|
return 0;
|
2021-04-23 00:44:27 +01:00
|
|
|
}
|