From e3f23a1427c5fc4108d6d655b48120cd189f6259 Mon Sep 17 00:00:00 2001 From: true Date: Sun, 5 Nov 2023 10:28:50 -0800 Subject: [PATCH] Add radar sweep background pattern --- src/main.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++------ src/sin1.c | 24 ++++++++++++----- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0062702..4e2207d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,6 +104,23 @@ void render_drot_border(int8_t x_width, uint16_t text_color, uint16_t border_col } } } + + for (x = 0; x < x_width; x++) { + is_color = 0; + for (y = 0; y < ROT_SIZE; y++) { + if (is_color) { + if (src[x + (y * ROT_SIZE)] != text_color) { + is_color = 0; + src[x + (y * ROT_SIZE)] = border_color; + } + } else { + if (src[x + (y * ROT_SIZE)] == text_color) { + is_color = 1; + src[x + (y * ROT_SIZE) - ROT_SIZE] = border_color; + } + } + } + } } void render_drot_rotate(int16_t x_width, int16_t rot, int16_t out_x, int16_t out_y) @@ -147,7 +164,7 @@ void render_drot_rotate(int16_t x_width, int16_t rot, int16_t out_x, int16_t out } } -void text_print_circular(const char *str, uint8_t text_size, int16_t spacing, uint16_t color, int16_t rot) +void text_print_circular(const char *str, uint8_t text_size, int16_t spacing, uint16_t fcolor, uint16_t bcolor, int16_t rot) { uint8_t i; int16_t x_width; @@ -165,14 +182,15 @@ void text_print_circular(const char *str, uint8_t text_size, int16_t spacing, ui y = sin1(rot); y = (y >> 9) + (y >> 11) + (y >> 12); - x_width = render_drot_printchar(str, i, text_size, color); // render character - render_drot_border(x_width, color, TEXT_BORDER_COLOR); // add border to character + x_width = render_drot_printchar(str, i, text_size, fcolor); // render character + render_drot_border(x_width, fcolor, bcolor); // add border to character render_drot_rotate(x_width, rot + 0x6000, x, y); rot -= spacing; } } -int16_t rot = 0; +int16_t trot = 0; +int16_t brot = 0; #define HUE_MIN 0x2000-300 #define HUE_MAX 0x2000+300 @@ -250,6 +268,39 @@ void bg_rainbow_circles(uint8_t saturation) } } +void bg_radarsweep(int16_t rot, int16_t offset, uint8_t lines) +{ + color_rgb rgb; + uint16_t w; + + int16_t x, y; + + if (lines == 0xff) lines--; + + dout->fillScreen(BLACK); + + for (uint8_t i = 0; i < lines; i++) { + // linear fade + w = 256 * lines; + w -= (256 * i); + w /= lines; + w &= 0xff; + + // todo: exponential fade or something + + // get rotational point + x = cos1(rot); + x = (x >> 8); + + y = sin1(rot); + y = (y >> 8); + + hsv2rgb_8b((1536/3), 200, (i > 4) ? (w >> 1) : w, &rgb.r, &rgb.g, &rgb.b); + dout->drawLine(x + 120, y + 120, 128, 128, dout->color565(rgb.r, rgb.g, rgb.b)); + rot -= offset; + } +} + void texthue_180degree() { uint16_t hue; @@ -272,19 +323,26 @@ void texthue_huesatcycle_circles() void loop() { uint16_t hue; + color_rgb fc, bc; // rainbow circles program - bg_rainbow_circles(200); + // bg_rainbow_circles(200); // texthue_180degree(); + brot += 400; + bg_radarsweep(brot, 25, 200); // small hue shift with larger saturation shifts circles // bg_huesatcycle_circles(); // texthue_huesatcycle(); // text rotation - black text, default border - rot += 420 - 69; - rgb.r = rgb.g = rgb.b = 0; - text_print_circular(name, TEXT_MAX_SIZE, LETTER_SPACING, dout->color565(rgb.r, rgb.g, rgb.b), rot); + trot += 420 - 69; + fc.r = fc.g = fc.b = 240; + bc.r = bc.g = bc.b = 32; + text_print_circular(name, TEXT_MAX_SIZE, LETTER_SPACING, + dout->color565(fc.r, fc.g, fc.b), + dout->color565(bc.r, bc.g, bc.b), + trot); dout->flush(); } \ No newline at end of file diff --git a/src/sin1.c b/src/sin1.c index b34e1f2..1d4b84d 100644 --- a/src/sin1.c +++ b/src/sin1.c @@ -22,7 +22,7 @@ * "5 bit" large table = 32 values. The mask: all bit belonging to the table * are 1, the all above 0. */ -#define TABLE_BITS (5) +#define TABLE_BITS (7) #define TABLE_SIZE (1<