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
|
// main.cpp
|
||||||
|
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
|
#include "background_dark_inverted.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define TARGET_TX_PIN USBTX
|
#define TARGET_TX_PIN USBTX
|
||||||
#define TARGET_RX_PIN USBRX
|
#define TARGET_RX_PIN USBRX
|
||||||
@@ -21,61 +24,42 @@ DigitalOut led(LED1);
|
|||||||
#define BUFFER_SIZE 64
|
#define BUFFER_SIZE 64
|
||||||
static char rx_buffer[BUFFER_SIZE];
|
static char rx_buffer[BUFFER_SIZE];
|
||||||
|
|
||||||
// Draw a moving “sky + ground” background with optional message
|
// ASCII fart background
|
||||||
void draw_mask(uint32_t mask, int shift, const char *text = nullptr)
|
void draw_mask(const char *unused_filename, int shift, const char *text = nullptr) {
|
||||||
{
|
const int view_width = 50; // visible width
|
||||||
const int width = 80; // terminal columns
|
const int view_height = 24;
|
||||||
const int height = 24; // terminal rows
|
|
||||||
const int horizon = 16; // sky ends here, ground below
|
|
||||||
|
|
||||||
printf("\033[2J\033[H"); // clear + home
|
// Terminal clear + home
|
||||||
|
printf("\033[2J\033[H");
|
||||||
|
|
||||||
// draw sky layer (moving clouds)
|
for (int i = 0; i < view_height && i < BACKGROUND_DARK_INVERTED_LINES; i++) {
|
||||||
for (int y = 0; y < horizon; y++) {
|
const char *row = BACKGROUND_DARK_INVERTED[i];
|
||||||
for (int x = 0; x < width; x++) {
|
int width = strlen(row);
|
||||||
// Parallax: slower movement at top
|
if (width == 0) {
|
||||||
int move = (shift / 2 + y) % width;
|
printf("\r\n");
|
||||||
char c = ((x + move) % 11 == 0) ? '☁' : ' ';
|
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("%c", c);
|
||||||
}
|
}
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw horizon line
|
if (text && text[0] != '\0')
|
||||||
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') {
|
|
||||||
printf("\r\n[RX] %s\r\n", text);
|
printf("\r\n[RX] %s\r\n", text);
|
||||||
}
|
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
serial_port.set_format(8, BufferedSerial::None, 1);
|
serial_port.set_format(8, BufferedSerial::None, 1);
|
||||||
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
|
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
|
||||||
|
|
||||||
uint32_t mask = 0xF0F0A55A;
|
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
char message[BUFFER_SIZE] = {0};
|
char message[BUFFER_SIZE] = {0};
|
||||||
bool message_active = false;
|
bool message_active = false;
|
||||||
@@ -84,6 +68,8 @@ int main(void)
|
|||||||
msg_timer.start();
|
msg_timer.start();
|
||||||
anim_timer.start();
|
anim_timer.start();
|
||||||
|
|
||||||
|
const char *bg_file = "background_dark_inverted.txt";
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (serial_port.readable()) {
|
if (serial_port.readable()) {
|
||||||
memset(rx_buffer, 0, sizeof(rx_buffer));
|
memset(rx_buffer, 0, sizeof(rx_buffer));
|
||||||
@@ -106,11 +92,11 @@ int main(void)
|
|||||||
// shift = (shift + 1) % 8;
|
// shift = (shift + 1) % 8;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
if (anim_timer.elapsed_time() >= 200ms) {
|
if (anim_timer.elapsed_time() >= 400ms) {
|
||||||
shift = (shift + 1) % 8;
|
shift++;
|
||||||
anim_timer.reset();
|
anim_timer.reset();
|
||||||
|
|
||||||
draw_mask(mask, shift, message_active ? message : nullptr);
|
draw_mask(bg_file, shift, message_active ? message : nullptr);
|
||||||
}
|
}
|
||||||
ThisThread::sleep_for(20ms);
|
ThisThread::sleep_for(20ms);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user