Make more interesting use of the palette mode
This commit is contained in:
parent
35a6298bb2
commit
1a37ef563b
1 changed files with 32 additions and 5 deletions
|
|
@ -10,6 +10,25 @@ DVHSTX8 display(DVHSTX_PINOUT_DEFAULT, DVHSTX_RESOLUTION_640x360);
|
|||
// The order is: {CKP, D0P, D1P, D2P} DVHSTX8 display({12, 14, 16, 18},
|
||||
// DVHSTX_RESOLUTION_640x360);
|
||||
|
||||
struct moving_point {
|
||||
int x, y, dx, dy;
|
||||
void step() {
|
||||
x += dx;
|
||||
if (x < 0) { x = 0; dx = random(3) + 1; }
|
||||
if (x >= display.width()) { x = display.width() - 1; dx = -random(3) - 1; }
|
||||
|
||||
y += dy;
|
||||
if (y < 0) { y = 0; dy = random(3) + 1; }
|
||||
if (y >= display.height()) { y = display.height() - 1; dy = -random(3) - 1; }
|
||||
}
|
||||
};
|
||||
|
||||
moving_point p1, p2;
|
||||
|
||||
int random_with_sign(int n) {
|
||||
return random(2) ? random(n-1)+1 : -random(n-1)-1;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// while(!Serial);
|
||||
|
|
@ -19,12 +38,20 @@ void setup() {
|
|||
digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
|
||||
}
|
||||
Serial.println("display initialized");
|
||||
p1 = moving_point{random(display.width()), random(display.height()), random_with_sign(3), random_with_sign(3)};
|
||||
p2 = moving_point{random(display.width()), random(display.height()), random_with_sign(3), random_with_sign(3)};
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Draw random lines
|
||||
display.drawLine(random(display.width()), random(display.height()),
|
||||
random(display.width()), random(display.height()),
|
||||
random(65536));
|
||||
sleep_ms(1);
|
||||
static int j;
|
||||
display.drawLine(p1.x, p1.y, p2.x, p2.y, 1 + (j + 254) % 255);
|
||||
Serial.printf("%d %d %d %d\r\n", p1.x, p1.y, p1.dx, p1.dy);
|
||||
p1.step();
|
||||
p2.step();
|
||||
|
||||
for(int i=1; i<256; i++) {
|
||||
display.setColor(i, ((i + j) % 255) * 0x010101);
|
||||
}
|
||||
j += 1;
|
||||
delay(3);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue