summaryrefslogtreecommitdiff
path: root/src/user/highway/vars.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/highway/vars.c')
-rw-r--r--src/user/highway/vars.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/user/highway/vars.c b/src/user/highway/vars.c
index ed9fa3a..2d53c3a 100644
--- a/src/user/highway/vars.c
+++ b/src/user/highway/vars.c
@@ -84,7 +84,7 @@ void dump_vars() {
}
static const char hex_digits[] = "0123456789abcdef";
-static char color[] = {'1', '0', '.', '.'};
+static char color[12] = "000000......";
static const struct no_null_sn color_name = {
.data = "_color",
@@ -93,12 +93,46 @@ static const struct no_null_sn color_name = {
static const struct no_null_sn color_value = {
.data = color,
- .length = 4
+ .length = 12
};
void new_color() {
- const uint8_t bg = gen_rand() % 0x30 + 0x38;
- color[2] = hex_digits[bg >> 4];
- color[3] = hex_digits[bg & 0xf];
+ const uint16_t hue = gen_rand() % (0x33 * 6);
+ _pixel_t bg = {.r = 0xff, .g = 0xcc, .b = 0xcc};
+ if (hue <= 0x33) {
+ bg.b += hue;
+ goto got_bg;
+ }
+ bg.b += 0x33;
+ if (hue <= 0x33 * 2) {
+ bg.r -= hue - 0x33;
+ goto got_bg;
+ }
+ bg.r -= 0x33;
+ if (hue <= 0x33 * 3) {
+ bg.g += hue - 0x33 * 2;
+ goto got_bg;
+ }
+ bg.g += 0x33;
+ if (hue <= 0x33 * 4) {
+ bg.b -= hue - 0x33 * 3;
+ goto got_bg;
+ }
+ bg.b -= 0x33;
+ if (hue <= 0x33 * 5) {
+ bg.r += hue - 0x33 * 4;
+ goto got_bg;
+ }
+ bg.r += 0x33;
+ bg.g -= hue - 0x33 * 5;
+
+got_bg:
+ color[ 6] = hex_digits[bg.r / 16];
+ color[ 7] = hex_digits[bg.r % 16];
+ color[ 8] = hex_digits[bg.g / 16];
+ color[ 9] = hex_digits[bg.g % 16];
+ color[10] = hex_digits[bg.b / 16];
+ color[11] = hex_digits[bg.b % 16];
+
set_var(color_name, color_value);
} \ No newline at end of file