Skip to content

Instantly share code, notes, and snippets.

@melpon
Last active April 12, 2019 02:27
Show Gist options
  • Save melpon/79cd7439122d0369f3def9c336b33913 to your computer and use it in GitHub Desktop.
Save melpon/79cd7439122d0369f3def9c336b33913 to your computer and use it in GitHub Desktop.
void screen_draw_rect(uint8_t screen[][4], uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
uint8_t masks[4] = { 0 };
uint8_t x2 = x + w;
while (x < x2) {
uint8_t n = x / 8;
uint8_t m = x % 8;
masks[n] |= (1 << (7 - m));
x++;
}
uint8_t y2 = y + h;
while (y < y2) {
for (uint8_t i = 0; i < 4; i++) {
screen[i][y] |= masks[i];
}
y++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment