From c0cb8634cbe2ce4bcf29873cd67d5735095b64a7 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 16 Apr 2021 13:26:22 +0200 Subject: Test drawing 0xbadd10de logo using line primitives --- src/main.c | 69 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/main.c b/src/main.c index d76273a..0261e8a 100644 --- a/src/main.c +++ b/src/main.c @@ -73,7 +73,7 @@ rgb15(u32 red, u32 green, u32 blue ) { #define COLOR_RED rgb15(31, 0, 12) #define COLOR_BLUE rgb15(2, 15, 30) #define COLOR_CYAN rgb15(0, 30, 30) -#define COLOR_GREY rgb15(10, 10, 10) +#define COLOR_GREY rgb15(4, 4, 4) #define COLOR_BLACK rgb15(0, 0, 0) #define COLOR_WHITE rgb15(28, 28, 28) @@ -307,44 +307,53 @@ u32 profile_stop() { } int main(void) { - DISP_CONTROL = DISP_MODE_4 | DISP_BG_2; + DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; - PAL_BUFFER[1] = COLOR_RED; - PAL_BUFFER[2] = COLOR_BLUE; + draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); - // Prepare the screen buffers by drawing a rectangle with different colors - // to each page. - draw_fill_rect_m4(0, 0, 20, 20, 1, SCREEN_PAGE_1); - draw_fill_rect_m4(0, 0, 20, 20, 2, SCREEN_PAGE_2); + int side = 60; + int x = 88; + int y = 70; + int line = 35; + int height = sqrt(side * side - (side / 2) * (side / 2)); - // Profile mode 4 vs mode 3 drawing fill_rects. - int n_iterations = 1000; - profile_start(); - for (size_t i = 0; i < n_iterations; ++i) { - draw_fill_rect_m4(0, 0, 20, 20, 1, SCREEN_PAGE_1); - } - u32 mode_4_count = profile_stop(); + // Draw red triangle. + draw_line(x + height - 1, y - side / 2, x, y - 1, COLOR_RED); + draw_line(x + height - 1, y + side / 2, x, y + 1, COLOR_RED); + draw_line(x + height - 1, y - side / 2 + 1, x, y, COLOR_RED); + draw_line(x + height - 1, y + side / 2 - 1, x, y, COLOR_RED); - DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; - profile_start(); - for (size_t i = 0; i < n_iterations; ++i) { - draw_fill_rect(0, 0, 20, 20, 1); - } - u32 mode_3_count = profile_stop(); + // Draw white triangle. + draw_line(x, y - side / 2, x, y + side / 2, COLOR_WHITE); + draw_line(x + 1, y - side / 2, x + height, y - 1, COLOR_WHITE); + draw_line(x + 1, y + side / 2, x + height, y + 1, COLOR_WHITE); - char msg[240]; - sprintf(&msg, "m4: %u", mode_4_count); - put_text(0, 0, COLOR_RED, msg); - sprintf(&msg, "m3: %u", mode_3_count); - put_text(0, 16, COLOR_RED, msg); + // Draw white line at triangle tip. + draw_line(x + height, y - side / 2, x + height, y + side / 2, COLOR_WHITE); + draw_line(x + height + 1, y - side / 2, x + height + 1, y + side / 2, COLOR_WHITE); + draw_line(x + height + 2, y - side / 2, x + height + 2, y + side / 2, COLOR_WHITE); + // draw_line(x + height + 3, y - side / 2, x + height + 3, y + side / 2, COLOR_WHITE); + + // Double triangle line. + draw_line(x - 1, y - side / 2, x - 1, y + side / 2, COLOR_WHITE); + draw_line(x + 1, y - side / 2 + 1, x + height, y, COLOR_WHITE); + draw_line(x + 1, y + side / 2 - 1, x + height, y, COLOR_WHITE); + + // Draw white lines. + draw_line(x - line, y, x, y, COLOR_WHITE); + draw_line(x + height, y, x + height + line, y, COLOR_WHITE); + draw_line(x - line, y + 1, x, y + 1, COLOR_WHITE); + draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); + + put_text(77, 125, COLOR_RED, "0xbadd10de"); int frame_counter = 0; while(true) { wait_vsync(); - // if (frame_counter++ > 30) { - // frame_counter = 0; - // flip_page(); - // } + if (frame_counter++ > 30) { + frame_counter = 0; + flip_page(); + } }; return 0; -- cgit v1.2.1