PageRenderTime 52ms CodeModel.GetById 17ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

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