From 8c2e538308b936066ca28fc0d5f78870ccd9d700 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 4 Mar 2020 17:02:48 +0000 Subject: [PATCH] Clear FizzleFade screen properly on init --- examples/fizzlefade/fizzlefade.cpp | 96 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/examples/fizzlefade/fizzlefade.cpp b/examples/fizzlefade/fizzlefade.cpp index da98adb86..d4fb6fc39 100644 --- a/examples/fizzlefade/fizzlefade.cpp +++ b/examples/fizzlefade/fizzlefade.cpp @@ -24,76 +24,78 @@ const uint16_t screen_height = 120; #define FADE_STEPS 3 Pen fade_to[FADE_STEPS]{ - Pen(128, 64, 15, 64), - Pen(15, 128, 15, 64), - Pen(15, 64, 128, 64) + Pen(128, 64, 15, 64), + Pen(15, 128, 15, 64), + Pen(15, 64, 128, 64) }; uint16_t taps[FADE_STEPS]{ - 0x74b8, - 0x50e7, - 0x6000 + 0x74b8, + 0x50e7, + 0x6000 }; int8_t fade_current = 0; /* setup */ void init() { - set_screen_mode(ScreenMode::lores); + set_screen_mode(ScreenMode::lores); - screen.alpha = 255; - screen.mask = nullptr; - screen.pen = fade_to[FADE_STEPS - 1]; - screen.clear(); + screen.alpha = 255; + screen.mask = nullptr; + Pen p = fade_to[FADE_STEPS - 1]; + p.a = 255; + screen.pen = p; + screen.clear(); - screen.pen = fade_to[0]; + screen.pen = fade_to[0]; } uint32_t lfsr = 1; uint16_t tap = 0x74b8; Point fizzlefade() { - uint16_t x = lfsr & 0x00ff; - uint16_t y = (lfsr & 0x7f00) >> 8; + uint16_t x = lfsr & 0x00ff; + uint16_t y = (lfsr & 0x7f00) >> 8; - uint8_t lsb = lfsr & 1; - lfsr >>= 1; + uint8_t lsb = lfsr & 1; + lfsr >>= 1; - if (lsb) { - lfsr ^= tap; - } + if (lsb) { + lfsr ^= tap; + } - if (x - 1 < 160 && y < 120) { - return Point(x - 1, y); - } + if (x - 1 < 160 && y < 120) { + return Point(x - 1, y); + } - return Point(-1, -1); + return Point(-1, -1); } void render(uint32_t time_ms) { - uint32_t ms_start = now(); - - screen.pen = fade_to[fade_current]; - - for (int c = 0; c < 500; c++) { - Point ff = fizzlefade(); - if (ff.x > -1) { - screen.pixel(ff); - } - if (lfsr == 1) { - fade_current += 1; - fade_current %= FADE_STEPS; - tap = taps[fade_current]; - break; - } - } - - uint32_t ms_end = now(); - screen.mask = nullptr; - screen.pen = Pen(255, 0, 0); - for (uint32_t i = 0; i < (ms_end - ms_start); i++) { - screen.pen = Pen(i * 5, 255 - (i * 5), 0); - screen.rectangle(Rect(i * 3 + 1, 117, 2, 2)); - } + uint32_t ms_start = now(); + + screen.pen = fade_to[fade_current]; + + for (int c = 0; c < 500; c++) { + Point ff = fizzlefade(); + if (ff.x > -1) { + screen.pixel(ff); + } + if (lfsr == 1) { + fade_current += 1; + fade_current %= FADE_STEPS; + tap = taps[fade_current]; + break; + } + } + + uint32_t ms_end = now(); + screen.mask = nullptr; + screen.pen = Pen(255, 0, 0); + for (uint32_t i = 0; i < (ms_end - ms_start); i++) { + screen.pen = Pen(i * 5, 255 - (i * 5), 0); + screen.rectangle(Rect(i * 3 + 1, 117, 2, 2)); + } } void update(uint32_t time) {