From 841225efbffdc1a9708070b03d7974f8dbf0f7ed Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 23 Jul 2024 10:58:33 +0100 Subject: [PATCH] PicoVector: Update C++ examples. --- .../pico_display_2/pico_display_2_vector.cpp | 13 +++++++------ .../pico_w_explorer/pico_w_explorer_vector.cpp | 17 +++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/pico_display_2/pico_display_2_vector.cpp b/examples/pico_display_2/pico_display_2_vector.cpp index 68e91554..47c2a468 100644 --- a/examples/pico_display_2/pico_display_2_vector.cpp +++ b/examples/pico_display_2/pico_display_2_vector.cpp @@ -42,16 +42,15 @@ int main() { pp_point_t outline[] = {{-64, -64}, {64, -64}, {64, 64}, {-64, 64}}; pp_point_t hole[] = {{ -32, 32}, { 32, 32}, { 32, -32}, { -32, -32}}; - pp_path_t paths[] = { - {.points = outline, .count = 4}, - {.points = hole, .count = 4} - }; - pp_poly_t poly = {.paths = paths, .count = 2}; + + pp_poly_t *poly = pp_poly_new(); + pp_path_add_points(pp_poly_add_path(poly), outline, sizeof(outline) / sizeof(pp_point_t)); + pp_path_add_points(pp_poly_add_path(poly), hole, sizeof(hole) / sizeof(pp_point_t)); pp_mat3_t pos = pp_mat3_identity(); pp_mat3_translate(&pos, 50, 50); pp_mat3_rotate(&pos, a); - vector.draw(&poly); + vector.draw(poly); vector.text("Hello World", &pos); // update screen @@ -60,6 +59,8 @@ int main() { if (a > 359) { a = 0; } + + pp_poly_free(poly); } return 0; diff --git a/examples/pico_w_explorer/pico_w_explorer_vector.cpp b/examples/pico_w_explorer/pico_w_explorer_vector.cpp index 20db5732..82cc29d8 100644 --- a/examples/pico_w_explorer/pico_w_explorer_vector.cpp +++ b/examples/pico_w_explorer/pico_w_explorer_vector.cpp @@ -31,16 +31,15 @@ int main() { pp_point_t outline[] = {{-128, -128}, {128, -128}, {128, 128}, {-128, 128}}; pp_point_t hole[] = {{ -64, 64}, { 64, 64}, { 64, -64}, { -64, -64}}; - pp_path_t paths[] = { - {.points = outline, .count = 4}, - {.points = hole, .count = 4} - }; - pp_poly_t poly = {.paths = paths, .count = 2}; - vector.rotate(&poly, {0, 0}, angle); - vector.translate(&poly, {160, 120}); + pp_poly_t *poly = pp_poly_new(); + pp_path_add_points(pp_poly_add_path(poly), outline, sizeof(outline) / sizeof(pp_point_t)); + pp_path_add_points(pp_poly_add_path(poly), hole, sizeof(hole) / sizeof(pp_point_t)); - vector.draw(&poly); + vector.rotate(poly, {0, 0}, angle); + vector.translate(poly, {160, 120}); + + vector.draw(poly); //pp_mat3_t t = pp_mat3_identity(); //vector.text("Hello World", {0, 0}, &t); @@ -49,6 +48,8 @@ int main() { st7789.update(&graphics); angle += 1.0f; + + pp_poly_free(poly); } return 0;