From e9dce46bed3cc0ec6993d09183ac858a32d619e2 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 12 Jan 2008 23:12:41 +0100 Subject: draw a spline --- src/CurveEditor.cxx | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/CurveEditor.cxx') diff --git a/src/CurveEditor.cxx b/src/CurveEditor.cxx index edc3a46..699261d 100644 --- a/src/CurveEditor.cxx +++ b/src/CurveEditor.cxx @@ -5,15 +5,49 @@ // of the GNU General Public License, incorporated herein by reference. #include -#include +#include #include +#include #include "CurveEditor.H" - CurveEditor::CurveEditor(int my_x, int my_y, int my_w, int my_h) : Fl_Widget(my_x, my_y, my_w, my_h) { + n = 3; + X = (double*) calloc(n, sizeof(double)); + Y = (double*) calloc(n, sizeof(double)); + + X[0] = 0.0; + Y[0] = 0.0; + + X[1] = 0.2; + Y[1] = 0.4; + + X[2] = 0.8; + Y[2] = 0.6; + + acc = gsl_interp_accel_alloc (); + spline = gsl_spline_alloc (gsl_interp_cspline, n); + gsl_spline_init (spline, X, Y, n); } +void +CurveEditor::draw() { + fl_color(FL_BLACK); + fl_rectf(x(), y(), w(), h()); + + fl_color(FL_WHITE); + fl_begin_line(); + for (double _x = 0.0; _x < 1.0; _x = _x + 0.01) { + double _y = gsl_spline_eval(spline, _x, acc); + + fl_vertex(x() + _x * w(), y() + h() * _y); + } + fl_end_line(); + + for (int i = 0; i < n; i++) { + fl_rect(x() + w() * X[i] - 2, y() + h() * Y[i] - 2, 4, 4); + } +} -- cgit v1.2.3