pimoroni-pico/examples/breakout_colourlcd240x240/demo.cpp

71 lines
1.6 KiB
C++
Raw Normal View History

2021-05-05 15:06:32 +01:00
#include <math.h>
#include <vector>
#include "generic_st7789.hpp"
using namespace pimoroni;
const int WIDTH = 240;
const int HEIGHT = 240;
ST7789Generic lcd(WIDTH, HEIGHT, false, nullptr, BG_SPI_FRONT);
2021-05-05 15:06:32 +01:00
int main() {
//lcd.configure_display(false);
lcd.set_backlight(255);
// 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;
Pen pen;
2021-05-05 15:06:32 +01:00
};
std::vector<pt> shapes;
for(int i = 0; i < 100; i++) {
2021-05-05 15:06:32 +01:00
pt shape;
shape.r = (rand() % 10) + 3;
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;
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);
}
Pen BG = lcd.create_pen(120, 40, 60);
Pen WHITE = lcd.create_pen(255, 255, 255);
while(true) {
lcd.set_pen(BG);
lcd.clear();
2021-05-05 15:06:32 +01:00
for(auto &shape : shapes) {
shape.x += shape.dx;
shape.y += shape.dy;
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);
}
lcd.set_pen(WHITE);
lcd.text("Hello World", Point(0, 0), 240);
2021-05-05 15:06:32 +01:00
// update screen
lcd.update();
}
2021-05-05 15:06:32 +01:00
return 0;
}