demo_plot.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <rtgui/widgets/plot.h>
  2. #include "demo_view.h"
  3. /* sin data */
  4. rt_int16_t sin_ydata[] = {
  5. 0, 9, 19, 29, 38, 47, 56, 64, 71, 78, 84, 89, 93, 96, 98, 99, 99, 99, 97,
  6. 94, 90, 86, 80, 74, 67, 59, 51, 42, 33, 23, 14, 4, -5, -15, -25, -35, -44,
  7. -52, -61, -68, -75, -81, -87, -91, -95, -97, -99, -99, -99, -98, -95, -92,
  8. -88, -83, -77, -70, -63, -55, -46, -37, -27, -18, -8, 1, 11, 21, 31
  9. };
  10. rt_int16_t cos_ydata[] = {
  11. 50, 49, 46, 41, 34, 27, 18, 8, -1, -11, -20, -29, -36, -42, -47, -49, -49,
  12. -48, -44, -39, -32, -24, -15, -5, 4, 14, 23, 31, 38, 44, 48, 49, 49, 47,
  13. 43, 37, 30, 21, 12, 2, -7, -16, -25, -33, -40, -45, -48, -49, -49, -46,
  14. -41, -35, -28, -19, -9, 0, 10, 19, 28, 36, 42, 46, 49, 49, 48, 45, 40, 33,
  15. 25, 16, 6, -3, -12, -22, -30, -37, -43, -47, -49, -49, -47, -44, -38, -31,
  16. -23, -13, -3, 6, 15, 24, 33, 39, 45, 48, 49, 49, 46, 42, 36, 29, 20, 10, 1,
  17. -8, -18, -27, -35, -41, -46, -49, -49, -48, -45, -41, -34, -26, -17, -8, 1,
  18. 11, 21, 29, 37, 43, 47, 49, 49, 48, 44, 39, 32, 24, 14, 5, -4, -14, -23,
  19. -32, -39, -44, -48, -49, -49, -47, -43, -37, -30, -21, -12, -2, 7, 17, 26,
  20. 34, 40, 45, 48, 49, 49, 46, 41, 35, 27, 18, 9, 0, -10, -20, -28, -36, -42,
  21. -46, -49, -49, -48, -45, -40, -33, -25, -16, -6, 3, 13, 22, 31, 38, 43, 47,
  22. 49, 49, 47, 43, 38
  23. };
  24. struct rtgui_container* demo_plot(void)
  25. {
  26. struct rtgui_container *cnt;
  27. struct rtgui_plot_curve *curve1, *curve2, *curve3;
  28. struct rtgui_plot *plot;
  29. struct rtgui_rect rect;
  30. cnt = demo_view("ÇúĎßťćÍź");
  31. curve1 = rtgui_plot_curve_create();
  32. curve1->y_data = sin_ydata;
  33. curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
  34. curve1->color = red;
  35. plot = rtgui_plot_create(curve1);
  36. curve2 = rtgui_plot_curve_create();
  37. curve2->y_data = cos_ydata;
  38. curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
  39. curve2->color = blue;
  40. rtgui_plot_append_curve(plot, curve2);
  41. curve3 = rtgui_plot_curve_create();
  42. curve3->x_data = cos_ydata;
  43. curve3->y_data = sin_ydata;
  44. curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
  45. curve3->color = black;
  46. rtgui_plot_append_curve(plot, curve3);
  47. rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect);
  48. rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect);
  49. rtgui_plot_set_base_point(plot,
  50. rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
  51. rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));
  52. return cnt;
  53. }