1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3 
4 #define CANVAS_WIDTH  300
5 #define CANVAS_HEIGHT  200
6 
timer_cb(lv_timer_t * timer)7 static void timer_cb(lv_timer_t * timer)
8 {
9     static int32_t counter = 0;
10     const char * string = "windstorrrrrrrrrrrrrrrrm~>>>";
11     const int16_t string_len = lv_strlen(string);
12 
13     lv_obj_t * canvas = lv_timer_get_user_data(timer);
14     lv_layer_t layer;
15     lv_canvas_init_layer(canvas, &layer);
16 
17     lv_canvas_fill_bg(canvas, lv_color_white(), LV_OPA_COVER);
18 
19     lv_draw_letter_dsc_t letter_dsc;
20     lv_draw_letter_dsc_init(&letter_dsc);
21     letter_dsc.color = lv_color_hex(0xff0000);
22     letter_dsc.font = lv_font_default();
23 
24     {
25 #define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10)
26 #define CURVE2_Y(t, T) ((t) * lv_trigo_sin(((t) + (T)) * 5) * 40 / 32767 / 80 + CANVAS_HEIGHT / 2)
27 
28         int32_t pre_x = CURVE2_X(-1);
29         int32_t pre_y = CURVE2_Y(-1, 0);
30         for(int16_t i = 0; i < string_len; i++) {
31             const int32_t angle = i * 5;
32             const int32_t x = CURVE2_X(angle);
33             const int32_t y = CURVE2_Y(angle + 30, counter / 2);
34 
35             letter_dsc.unicode = (uint32_t)string[i % string_len];
36             letter_dsc.rotation = lv_atan2(y - pre_y, x - pre_x) * 10;
37             letter_dsc.color = lv_color_hsv_to_rgb(i * 10, 100, 100);
38             lv_draw_letter(&layer, &letter_dsc, &(lv_point_t) {
39                 .x = x, .y = y
40             });
41 
42             pre_x = x;
43             pre_y = y;
44         }
45     }
46 
47     lv_canvas_finish_layer(canvas, &layer);
48 
49     counter++;
50 }
51 
lv_example_canvas_10(void)52 void lv_example_canvas_10(void)
53 {
54     /*Create a buffer for the canvas*/
55     LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
56     LV_DRAW_BUF_INIT_STATIC(draw_buf);
57 
58     lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
59     lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT);
60 
61     lv_obj_center(canvas);
62 
63     lv_canvas_set_draw_buf(canvas, &draw_buf);
64 
65     lv_timer_create(timer_cb, 16, canvas);
66 }
67 
68 #endif
69