Add draw arbitrary line.
This commit is contained in:
parent
2baddfc76e
commit
0297598438
53
src/main.c
53
src/main.c
@ -192,6 +192,42 @@ void draw_simple_line(uint16_t x, uint16_t y, uint16_t len, bool horizontal)
|
||||
}
|
||||
}
|
||||
|
||||
void draw_line(uint16_t _x0, uint16_t _y0, uint16_t _x1, uint16_t _y1, bool fill)
|
||||
{
|
||||
const float x0 = _x0;
|
||||
const float y0 = _y0;
|
||||
const float x1 = _x1;
|
||||
const float y1 = _y1;
|
||||
|
||||
if (x0 != x1)
|
||||
{
|
||||
const uint16_t x_begin = MIN(x0, x1);
|
||||
const uint16_t x_end = MAX(x0, x1);
|
||||
|
||||
for (uint16_t x = x_begin; x < x_end; ++x)
|
||||
{
|
||||
const uint16_t y = (y1 - y0) * (x - x0) / (x1 - x0) + y0;
|
||||
if (fill)
|
||||
set_pixel(x, y);
|
||||
else
|
||||
clear_pixel(x, y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint16_t y_begin = MIN(y0, y1);
|
||||
const uint16_t y_end = MAX(y0, y1);
|
||||
|
||||
for (uint16_t y = y_begin; y < y_end; ++y)
|
||||
{
|
||||
if (fill)
|
||||
set_pixel(x0, y);
|
||||
else
|
||||
clear_pixel(x0, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void new_frame_handler(void)
|
||||
{
|
||||
if (vga_pixel_ptr && dma_ready)
|
||||
@ -251,10 +287,19 @@ int main()
|
||||
set_pixel(x, (x / 32) * 4 + 120);
|
||||
}
|
||||
// draw "E" - nice because it's not symmetrical along X
|
||||
draw_simple_line(100, 100, 8, true);
|
||||
draw_simple_line(100, 100, 8, false);
|
||||
draw_simple_line(100, 104, 8, true);
|
||||
draw_simple_line(100, 108, 8, true);
|
||||
draw_line(100, 100, 108, 100, true);
|
||||
draw_line(100, 100, 100, 108, true);
|
||||
draw_line(100, 104, 104, 104, true);
|
||||
draw_line(100, 108, 108, 108, true);
|
||||
|
||||
for (uint16_t x = 0; x < 480; x += 20)
|
||||
{
|
||||
draw_line(x, 0, 0, 480 - x, true);
|
||||
draw_line(480, x, 480 - x, 480, true);
|
||||
}
|
||||
|
||||
draw_line(200, 200, 280, 78, true);
|
||||
draw_line(87, 42, 42, 87, true);
|
||||
|
||||
// Running programs on PIO
|
||||
PIORun vga_hsync, vga_vsync, vga_pixel;
|
||||
|
Loading…
Reference in New Issue
Block a user