Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear FizzleFade screen properly on init #271

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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