Mercurial > MadButterfly
comparison src/X_main.c @ 19:cf6d65398619
More animation demo
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 02 Aug 2008 15:38:54 +0800 |
parents | 0f3baa488a62 |
children | 74d3d5dc9aaa |
comparison
equal
deleted
inserted
replaced
18:0f3baa488a62 | 19:cf6d65398619 |
---|---|
12 | 12 |
13 Display *display; | 13 Display *display; |
14 | 14 |
15 void draw_path(cairo_t *cr, int w, int h) { | 15 void draw_path(cairo_t *cr, int w, int h) { |
16 redraw_man_t rdman; | 16 redraw_man_t rdman; |
17 shape_t *path; | 17 shape_t *path1, *path2; |
18 coord_t *coord; | 18 coord_t *coord1, *coord2; |
19 paint_t *fill; | 19 paint_t *fill1, *fill2; |
20 int i; | 20 int i; |
21 | 21 |
22 redraw_man_init(&rdman, cr); | 22 redraw_man_init(&rdman, cr); |
23 coord = rdman.root_coord; | 23 coord1 = rdman_coord_new(&rdman, rdman.root_coord); |
24 coord2 = rdman_coord_new(&rdman, rdman.root_coord); | |
24 | 25 |
25 fill = paint_color_new(&rdman, 1, 1, 0); | 26 fill1 = paint_color_new(&rdman, 1, 1, 0); |
26 path = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); | 27 fill2 = paint_color_new(&rdman, 0, 1, 1); |
27 rdman_paint_fill(&rdman, fill, path); | 28 path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); |
28 coord->matrix[0] = 0.8; | 29 rdman_paint_fill(&rdman, fill1, path1); |
29 coord->matrix[1] = 0; | 30 coord1->matrix[0] = 0.8; |
30 coord->matrix[2] = 20; | 31 coord1->matrix[1] = 0; |
31 coord->matrix[4] = 0.8; | 32 coord1->matrix[2] = 20; |
32 coord->matrix[5] = 20; | 33 coord1->matrix[4] = 0.8; |
33 rdman_coord_changed(&rdman, coord); | 34 coord1->matrix[5] = 20; |
34 rdman_add_shape(&rdman, (shape_t *)path, coord); | 35 path2 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); |
36 rdman_paint_fill(&rdman, fill2, path2); | |
37 coord2->matrix[0] = -0.8; | |
38 coord2->matrix[1] = 0; | |
39 coord2->matrix[2] = 220; | |
40 coord2->matrix[4] = 0.8; | |
41 coord2->matrix[5] = 20; | |
42 rdman_coord_changed(&rdman, coord1); | |
43 rdman_coord_changed(&rdman, coord2); | |
44 rdman_add_shape(&rdman, (shape_t *)path1, coord1); | |
45 rdman_add_shape(&rdman, (shape_t *)path2, coord2); | |
35 | 46 |
36 rdman_redraw_all(&rdman); | 47 rdman_redraw_all(&rdman); |
37 | 48 |
38 XFlush(display); | 49 XFlush(display); |
39 | 50 |
40 for(i = 0; i < 50; i++) { | 51 for(i = 0; i < 50; i++) { |
41 usleep(20000); | 52 usleep(20000); |
42 coord->matrix[2] += 1; | 53 coord1->matrix[2] += 1; |
43 coord->matrix[5] += 1; | 54 coord1->matrix[5] += 1; |
44 paint_color_set(fill, 1, 1, (i/25) & 0x1); | 55 coord2->matrix[2] -= 1; |
45 rdman_coord_changed(&rdman, coord); | 56 coord2->matrix[5] += 1; |
57 paint_color_set(fill1, 1, 1, (i/25) & 0x1); | |
58 paint_color_set(fill2, (i/25) & 0x1, 1, 1); | |
59 rdman_paint_changed(&rdman, fill1); | |
60 rdman_paint_changed(&rdman, fill2); | |
61 rdman_coord_changed(&rdman, coord1); | |
62 rdman_coord_changed(&rdman, coord2); | |
46 rdman_redraw_changed(&rdman); | 63 rdman_redraw_changed(&rdman); |
47 XFlush(display); | 64 XFlush(display); |
48 } | 65 } |
49 | 66 |
50 for(i = 0; i < 5; i++) { | 67 for(i = 0; i < 5; i++) { |
51 usleep(500000); | 68 usleep(500000); |
52 paint_color_set(fill, 1, i % 2, 0); | 69 paint_color_set(fill1, 1, i % 2, 0); |
53 rdman_paint_changed(&rdman, fill); | 70 paint_color_set(fill2, 0, i % 2, 1); |
71 rdman_paint_changed(&rdman, fill1); | |
72 rdman_paint_changed(&rdman, fill2); | |
54 rdman_redraw_changed(&rdman); | 73 rdman_redraw_changed(&rdman); |
55 XFlush(display); | 74 XFlush(display); |
56 } | 75 } |
57 | 76 |
58 fill->free(fill); | 77 fill1->free(fill1); |
78 fill2->free(fill2); | |
59 redraw_man_destroy(&rdman); | 79 redraw_man_destroy(&rdman); |
60 sh_path_free(path); | 80 sh_path_free(path1); |
81 sh_path_free(path2); | |
61 } | 82 } |
62 | 83 |
63 void drawing(cairo_surface_t *surface, int w, int h) { | 84 void drawing(cairo_surface_t *surface, int w, int h) { |
64 cairo_t *cr; | 85 cairo_t *cr; |
65 | 86 |