kopia lustrzana https://github.com/pimoroni/pimoroni-pico
60 wiersze
1.4 KiB
C++
60 wiersze
1.4 KiB
C++
#include <math.h>
|
|
#include <vector>
|
|
|
|
#include "drivers/st7735/st7735.hpp"
|
|
#include "libraries/pico_graphics/pico_graphics.hpp"
|
|
|
|
using namespace pimoroni;
|
|
|
|
ST7735 st7735(160, 80, get_spi_pins(BG_SPI_FRONT));
|
|
PicoGraphics_PenP8 graphics(st7735.width, st7735.height, nullptr);
|
|
|
|
int main() {
|
|
st7735.set_backlight(255);
|
|
|
|
struct pt {
|
|
float x;
|
|
float y;
|
|
uint8_t r;
|
|
float dx;
|
|
float dy;
|
|
Pen pen;
|
|
};
|
|
|
|
std::vector<pt> shapes;
|
|
for(int i = 0; i < 1000; i++) {
|
|
pt shape;
|
|
shape.x = rand() % graphics.bounds.w;
|
|
shape.y = rand() % graphics.bounds.h;
|
|
shape.r = (rand() % 10) + 3;
|
|
shape.dx = float(rand() % 255) / 128.0f;
|
|
shape.dy = float(rand() % 255) / 128.0f;
|
|
shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255);
|
|
shapes.push_back(shape);
|
|
}
|
|
|
|
uint8_t bg = graphics.create_pen(120, 40, 60);
|
|
|
|
while(true) {
|
|
graphics.set_pen(bg);
|
|
graphics.clear();
|
|
|
|
for(auto &shape : shapes) {
|
|
shape.x += shape.dx;
|
|
shape.y += shape.dy;
|
|
if(shape.x < 0) shape.dx *= -1;
|
|
if(shape.x >= graphics.bounds.w) shape.dx *= -1;
|
|
if(shape.y < 0) shape.dy *= -1;
|
|
if(shape.y >= graphics.bounds.h) shape.dy *= -1;
|
|
|
|
graphics.set_pen(shape.pen);
|
|
graphics.circle(Point(shape.x, shape.y), shape.r);
|
|
}
|
|
|
|
// update screen
|
|
st7735.update(&graphics);
|
|
}
|
|
|
|
return 0;
|
|
}
|