/packages/xforms/examples/chartstrip.pp

https://github.com/slibre/freepascal · Puppet · 121 lines · 101 code · 20 blank · 0 comment · 0 complexity · ea70dac79415f5eee0da47019f6f80d9 MD5 · raw file

  1. { A demo of a moving chart }
  2. program chartstrip;
  3. uses xforms,xlib;
  4. var
  5. func : longint;
  6. xx : double;
  7. step : double;
  8. form : PFL_FORM;
  9. chartobj,sinobj,exitbut,stepobj : PFL_OBJECT;
  10. procedure set_function(obj : PFL_OBJECT; arg : longint);cdecl;
  11. begin
  12. func := arg;
  13. fl_clear_chart(chartobj);
  14. xx := 0.0;
  15. end;
  16. procedure set_step(obj : PFL_OBJECT; arg : longint);cdecl;
  17. begin
  18. step := fl_get_slider_value(stepobj);
  19. end;
  20. {***********************************************}
  21. procedure create_form_form;
  22. var obj : PFL_OBJECT;
  23. begin
  24. form := fl_bgn_form(FL_NO_BOX,490,320);
  25. obj := fl_add_box(FL_BORDER_BOX,0,0,490,320,'');
  26. obj := fl_add_chart(FL_LINE_CHART,20,160,390,140,'');
  27. chartobj := obj;
  28. fl_set_object_dblbuffer(obj,1);
  29. fl_bgn_group();
  30. obj := fl_add_lightbutton(FL_RADIO_BUTTON,30,120,170,30,'sin(x)');
  31. sinobj := obj ;
  32. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  33. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),1);
  34. obj := fl_add_lightbutton(FL_RADIO_BUTTON,30,90,170,30,'sin(2x)*cos(x)');
  35. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  36. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),2);
  37. obj := fl_add_lightbutton(FL_RADIO_BUTTON,30,60,170,30,'sin(2x)+cos(x)');
  38. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  39. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),3);
  40. obj := fl_add_lightbutton(FL_RADIO_BUTTON,240,120,160,30,'sin(3x)+cos(x)');
  41. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  42. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),4);
  43. obj := fl_add_lightbutton(FL_RADIO_BUTTON,240,90,160,30,'sin(x)^2 + cos(x)');
  44. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  45. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),5);
  46. obj := fl_add_lightbutton(FL_RADIO_BUTTON,240,60,160,30,'sin(x)^3');
  47. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  48. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_function),6);
  49. fl_end_group();
  50. obj := fl_add_button(FL_NORMAL_BUTTON,150,20,140,30,'Exit');
  51. exitbut := obj;
  52. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  53. obj:= fl_add_valslider(FL_VERT_SLIDER,430,20,40,280,'');
  54. stepobj := obj ;
  55. fl_set_object_boxtype(obj,FL_BORDER_BOX);
  56. fl_set_object_callback(obj,PFL_CALLBACKPTR(@set_step),0);
  57. fl_end_form;
  58. end;
  59. {**********************************}
  60. function next_step : double;
  61. var res : double;
  62. begin
  63. res := 0.0;
  64. case func of
  65. 1: res := sin(xx);
  66. 2: res := sin(2*xx)*cos(xx);
  67. 3: res := sin(2*xx)+cos(xx);
  68. 4: res := sin(3*xx)+cos(xx);
  69. 5: res := sin(xx)*sin(xx) + cos(xx);
  70. 6: res := sin(xx)*sin(xx)*sin(xx);
  71. end;
  72. xx := xx+step;
  73. next_step:=res;
  74. end;
  75. function idle_cb (ex : PXEvent; d : pointer) : longint;
  76. begin
  77. fl_insert_chart_value(chartobj,1,next_step(),'',1);
  78. end;
  79. var obj : PFL_OBJECT;
  80. begin
  81. func:= 1;
  82. xx:= 0.0;
  83. step:= 0.15;
  84. fl_flip_yorigin();
  85. fl_initialize(@argc, argv, 'FormDemo', nil, 0);
  86. create_form_form();
  87. fl_set_chart_bounds(chartobj,-1.5,1.5);
  88. fl_set_chart_maxnumb(chartobj,80);
  89. fl_set_chart_autosize(chartobj,0);
  90. fl_set_button(sinobj,1);
  91. fl_set_slider_value(stepobj,0.15);
  92. fl_set_slider_bounds(stepobj,0.0,0.4);
  93. {$ifdef nevertrue}
  94. fl_set_idle_delta(15);
  95. {$endif }
  96. fl_show_form(form,FL_PLACE_CENTER,FL_NOBORDER,'StripChart');
  97. repeat
  98. fl_insert_chart_value(chartobj,1,next_step(),'',1);
  99. obj := fl_check_forms();
  100. until obj = exitbut;
  101. end.