Skip to content

Commit

Permalink
Merge pull request #271 from Gadgetoid/patch-fizzlefade
Browse files Browse the repository at this point in the history
Clear FizzleFade screen properly on init
  • Loading branch information
Gadgetoid authored Mar 4, 2020
2 parents 852187e + 8c2e538 commit 440522c
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions examples/fizzlefade/fizzlefade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 440522c

Please sign in to comment.