Add 'GLG Programs' brand.

This commit is contained in:
giomba 2022-12-02 22:34:00 +01:00
parent 0297598438
commit 8af09d4a6e
1 changed files with 92 additions and 43 deletions

View File

@ -253,53 +253,102 @@ void new_frame_handler(void)
pio_interrupt_clear(pio0_hw, 1);
}
typedef struct Point
{
uint16_t x;
uint16_t y;
} Point;
typedef struct Letter
{
char letter;
size_t len;
Point *points;
} Letter;
// just because i did not need all the letters
// and didn't want to fill a proper array :-)
const Letter letters[] = {
{'A', 6, (Point[]){{0, 7}, {0, 0}, {7, 0}, {7, 7}, {7, 3}, {0, 3}}},
{'G', 6, (Point[]){{7, 0}, {0, 0}, {0, 7}, {7, 7}, {7, 3}, {3, 3}}},
{'L', 3, (Point[]){{0, 0}, {0, 7}, {7, 7}}},
{'M', 5, (Point[]){{0, 7}, {0, 0}, {3, 3}, {7, 0}, {7, 7}}},
{'O', 5, (Point[]){{0, 0}, {0, 7}, {7, 7}, {7, 0}, {0, 0}}},
{'P', 5, (Point[]){{0, 7}, {0, 0}, {7, 0}, {7, 3}, {0, 3}}},
{'R', 6, (Point[]){{0, 7}, {0, 0}, {7, 0}, {7, 3}, {0, 3}, {7, 7}}},
{'S', 6, (Point[]){{0, 7}, {7, 7}, {7, 3}, {0, 3}, {0, 0}, {7, 0}}},
};
void draw_path(uint16_t x, uint16_t y, Point points[], size_t len)
{
Point *old_point = &points[0];
for (int i = 1; i < len; ++i)
{
Point *current_point = &points[i];
draw_line(x + old_point->x, y + old_point->y, x + current_point->x, y + current_point->y,
true);
old_point = current_point;
}
}
void draw_letter(uint16_t x, uint16_t y, char c)
{
for (int i = 0; i < count_of(letters); ++i)
{
if (letters[i].letter == c)
{
draw_path(x, y, letters[i].points, letters[i].len);
break;
}
}
}
void draw_string(uint16_t x, uint16_t y, const char *s)
{
while (*s != 0)
{
draw_letter(x, y, *s);
s++;
x += 9;
}
}
void draw_demo(void)
{
// draw a little demo
// clear frame buffer
memset(&frame[0], 0, sizeof(frame));
// horizontal lines
draw_line(0, 0, 640 - 1, 0, true);
draw_line(0, 240 - 1, 640 - 1, 240 - 1, true);
draw_line(0, 480 - 1, 640 - 1, 480 - 1, true);
// vertical lines
draw_line(0, 0, 0, 480 - 1, true);
draw_line(320 - 1, 0, 320 - 1, 480 - 1, true);
draw_line(638, 0, 638, 480 - 1, true); // last pixel of a line can't be set, see set_pixel()
// cat eye
for (uint16_t x = 0; x < 640; x += 20)
{
draw_line(x, 0, 0, (480 - x * 480 / 640), true);
draw_line(640, x * 480 / 640, 640 - x, 480, true);
}
// string
draw_string(200, 200, "GLG PROGRAMS");
}
int main()
{
setup_clocks();
stdio_init_all();
sleep_ms(1000);
// clear frame buffer
memset(&frame[0], 0, sizeof(frame));
// draw a cross
// horizontal lines
for (uint16_t x = 0; x < 640; ++x)
{
if ((x / 32) % 2 == 0)
set_pixel(x, 0);
if ((x / 32) % 2 == 1)
set_pixel(x, 2);
set_pixel(x, 239);
set_pixel(x, 479);
}
// vertical lines
for (uint16_t y = 0; y < 480; ++y)
{
set_pixel(0 + (y / 10) * 4, y);
set_pixel(0, y);
set_pixel(319, y);
// rightmost pixels can't be set, see description
set_pixel(638, y);
}
// try to find strangeness using stairs
for (uint16_t x = 0; x < 640; ++x)
{
set_pixel(x, (x / 32) * 4 + 120);
}
// draw "E" - nice because it's not symmetrical along X
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);
draw_demo();
// Running programs on PIO
PIORun vga_hsync, vga_vsync, vga_pixel;
@ -373,10 +422,10 @@ int main()
for (;;)
{
// fancy drawings
// moving sine
const uint16_t fc = frame_counter;
const uint16_t x = fc % 640;
const uint16_t y = 239 + 100 * (abs(320 - x) / 640.0) * sin((fc % 640) / 12.738);
const uint16_t y = 380 + 100 * (abs(320 - x) / 640.0) * sin((fc % 640) / 12.738);
if ((fc / 640) % 2)
set_pixel(x, y);
else