From 189da15810deabd739d7c11c6e95fea55739fe60 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 1 Aug 2020 15:13:49 +0200 Subject: Initial import from archive --- src/colwheel.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/colwheel.c (limited to 'src/colwheel.c') diff --git a/src/colwheel.c b/src/colwheel.c new file mode 100644 index 0000000..95f551c --- /dev/null +++ b/src/colwheel.c @@ -0,0 +1,153 @@ +/* + * colwheel.c + * + * Colour wheel definition and visualisation + * + * (c) 2006-2007 Thomas White + * + * Synth2D - two-dimensional Fourier synthesis + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "displaywindow.h" + +#define COLWHEEL_WIDTH 256 +#define COLWHEEL_SIZE ((COLWHEEL_WIDTH)-1) +#define COLWHEEL_HALF ((COLWHEEL_WIDTH/2)-1) + +#define rad2deg(a) ((a)*180.0/M_PI) +#define deg2rad(a) ((a)*M_PI/180.0) + +gint colwheel_show(GtkWidget *widget, gpointer data) { + + GtkWidget *colwheel_window; + GdkPixbuf *colwheel_pixbuf; + GtkWidget *colwheel_pixmap_widget; + fftw_complex *colwheel; + + unsigned int x, y; + double am, ph; + + /* This isn't being transformed, so no need to use fftw_malloc() */ + colwheel = malloc(COLWHEEL_SIZE*COLWHEEL_SIZE*sizeof(fftw_complex)); + for ( x=0; x= 360.0 ) ph = 0.0; + d = ph / 60.0; + + hi = floor(d); /* Divide the colour wheel into six sections */ + f = d - hi; /* Distance into the current section of the colour wheel */ + if ( hi == 6 ) hi = 0; + switch ( hi ) { + case 0 : return am; + case 1 : return am; + case 2 : return am*(1.0-f); + case 3 : return 0.0; + case 4 : return am*f/2.0; + case 5 : return am/2.0+am*f/2.0; + default : return 0.0; + } + +} + +double colwheel_green(double am, double ph) { + + double f; + unsigned int hi; + double d; + + ph = rad2deg(ph); /* Convert to degrees */ + ph += 180.0; /* Rotation of colour wheel */ + if ( ph >= 360.0 ) ph = 0.0; + d = ph / 60.0; + + hi = floor(d); /* Divide the colour wheel into six sections */ + f = d - hi; /* Distance into the current section of the colour wheel */ + if ( hi == 6 ) hi = 0; + switch ( hi ) { + case 0 : return am*f/2.0; + case 1 : return am/2.0+am*f/2.0; + case 2 : return am; + case 3 : return am*(1.0-f); + case 4 : return 0.0; + case 5 : return 0.0; + default : return 0.0; + } + +} + +double colwheel_red(double am, double ph) { + + double f; + unsigned int hi; + double d; + + ph = rad2deg(ph); /* Convert to degrees */ + ph += 180.0; /* Rotation of colour wheel */ + if ( ph >= 360.0 ) ph = 0.0; + d = ph / 60.0; + + hi = floor(d); /* Divide the colour wheel into six sections */ + f = d - hi; /* Distance into the current section of the colour wheel */ + if ( hi == 6 ) hi = 0; + switch ( hi ) { + case 0 : return 0.0; + case 1 : return 0.0; + case 2 : return 0.0; + case 3 : return am*f; + case 4 : return am; + case 5 : return am*(1.0-f); + default : return 0.0; + } + +} -- cgit v1.2.3