amazing ascii moving now from file
This commit is contained in:
17
semestralka1/background_dark_inverted.h
Normal file
17
semestralka1/background_dark_inverted.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// background_dark_inverted.h
|
||||
#pragma once
|
||||
|
||||
// embedded ASCII art background
|
||||
static const char *BACKGROUND_DARK_INVERTED[] = {
|
||||
"##################################################",
|
||||
"# #",
|
||||
"# example ASCII background line 1 #",
|
||||
"# replace this content with your real art #",
|
||||
"# #",
|
||||
"#================================================#",
|
||||
"# #",
|
||||
"# #",
|
||||
"##################################################"
|
||||
};
|
||||
static const int BACKGROUND_DARK_INVERTED_LINES =
|
||||
sizeof(BACKGROUND_DARK_INVERTED) / sizeof(BACKGROUND_DARK_INVERTED[0]);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
// main.cpp
|
||||
|
||||
#include "mbed.h"
|
||||
#include "background_dark_inverted.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#define TARGET_TX_PIN USBTX
|
||||
#define TARGET_RX_PIN USBRX
|
||||
@@ -21,61 +24,42 @@ DigitalOut led(LED1);
|
||||
#define BUFFER_SIZE 64
|
||||
static char rx_buffer[BUFFER_SIZE];
|
||||
|
||||
// Draw a moving “sky + ground” background with optional message
|
||||
void draw_mask(uint32_t mask, int shift, const char *text = nullptr)
|
||||
{
|
||||
const int width = 80; // terminal columns
|
||||
const int height = 24; // terminal rows
|
||||
const int horizon = 16; // sky ends here, ground below
|
||||
// ASCII fart background
|
||||
void draw_mask(const char *unused_filename, int shift, const char *text = nullptr) {
|
||||
const int view_width = 50; // visible width
|
||||
const int view_height = 24;
|
||||
|
||||
printf("\033[2J\033[H"); // clear + home
|
||||
// Terminal clear + home
|
||||
printf("\033[2J\033[H");
|
||||
|
||||
// draw sky layer (moving clouds)
|
||||
for (int y = 0; y < horizon; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
// Parallax: slower movement at top
|
||||
int move = (shift / 2 + y) % width;
|
||||
char c = ((x + move) % 11 == 0) ? '☁' : ' ';
|
||||
for (int i = 0; i < view_height && i < BACKGROUND_DARK_INVERTED_LINES; i++) {
|
||||
const char *row = BACKGROUND_DARK_INVERTED[i];
|
||||
int width = strlen(row);
|
||||
if (width == 0) {
|
||||
printf("\r\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
int start = shift % width;
|
||||
|
||||
// Print visible window (wrap around)
|
||||
for (int j = 0; j < view_width; j++) {
|
||||
char c = row[(start + j) % width];
|
||||
printf("%c", c);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
// draw horizon line
|
||||
for (int i = 0; i < width; i++) printf("-");
|
||||
printf("\r\n");
|
||||
|
||||
// draw ground (grass / terrain)
|
||||
for (int y = horizon + 1; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int move = (shift * 2 + y) % width;
|
||||
// simple wave pattern for terrain / hill
|
||||
char c;
|
||||
if (((x + move) % 7) == 0)
|
||||
c = '^';
|
||||
else if (((x + move) % 5) == 0)
|
||||
c = '`';
|
||||
else
|
||||
c = ' ';
|
||||
printf("%c", c);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
// optional text overlay at bottom
|
||||
if (text && text[0] != '\0') {
|
||||
if (text && text[0] != '\0')
|
||||
printf("\r\n[RX] %s\r\n", text);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
serial_port.set_format(8, BufferedSerial::None, 1);
|
||||
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
|
||||
|
||||
uint32_t mask = 0xF0F0A55A;
|
||||
int shift = 0;
|
||||
char message[BUFFER_SIZE] = {0};
|
||||
bool message_active = false;
|
||||
@@ -84,6 +68,8 @@ int main(void)
|
||||
msg_timer.start();
|
||||
anim_timer.start();
|
||||
|
||||
const char *bg_file = "background_dark_inverted.txt";
|
||||
|
||||
while (true) {
|
||||
if (serial_port.readable()) {
|
||||
memset(rx_buffer, 0, sizeof(rx_buffer));
|
||||
@@ -106,11 +92,11 @@ int main(void)
|
||||
// shift = (shift + 1) % 8;
|
||||
|
||||
// }
|
||||
if (anim_timer.elapsed_time() >= 200ms) {
|
||||
shift = (shift + 1) % 8;
|
||||
if (anim_timer.elapsed_time() >= 400ms) {
|
||||
shift++;
|
||||
anim_timer.reset();
|
||||
|
||||
draw_mask(mask, shift, message_active ? message : nullptr);
|
||||
draw_mask(bg_file, shift, message_active ? message : nullptr);
|
||||
}
|
||||
ThisThread::sleep_for(20ms);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user