Nice! Pretty cool. And nice layout of the window too.
Here’s my tiny addition to sine wave uses: A color spectrum. It’s not perfect though, colors are a bit off. Clipping off the bottom part helps (remove commenting in code). And maybe also the top, but then it’s not so much sine-like waves any more (more like triangle waves). But it’s kind of useless I guess.
Btw (as you probably know), you can make square waves out of sine waves.
As a fun tidbit, the opposite holds true too
Test program:
final float offset = 64;
final float clipping = 64;
final float normalize = 256 / (256-clipping);
float waveLRed = 256;
float phaseRed = offset;
float waveLBlu = 256;
float phaseBlu = (256/3.0)+offset;
float waveLGrn = 256;
float phaseGrn = 2*(256/3.0)+offset;
void setup() {
size(800,400);
//background(82, 82, 82);
int xOrigo = 100;
int yOrigo = height-100;
int xsize = 512;
int ysize = 256;
float xScale = xsize/256.0;
stroke(0);
// Axises
line(xOrigo-50, yOrigo, xOrigo+xsize, yOrigo);
line(xOrigo, yOrigo+50, xOrigo, yOrigo-ysize);
line(xOrigo+512, yOrigo+50, xOrigo+512, yOrigo-ysize);
// Draw graph
float redc, grnc, bluc;
int ox = 0;
float oldr = 0;
float oldg = 0;
float oldb = 0;
for (int x=0; x<xsize; x++) {
redc = 127.5 + 127.5 * sin( TWO_PI * (((x/xScale)/waveLRed) + phaseRed/waveLRed) );
grnc = 127.5 + 127.5 * sin( TWO_PI * (((x/xScale)/waveLGrn) + phaseGrn/waveLGrn) );
bluc = 127.5 + 127.5 * sin( TWO_PI * (((x/xScale)/waveLBlu) + phaseBlu/waveLBlu) );
/** // clip bottom
redc -= clipping;
grnc -= clipping;
bluc -= clipping;
if (redc<0) redc = 0;
if (grnc<0) grnc = 0;
if (bluc<0) bluc = 0;
redc = round(redc * normalize);
grnc = round(grnc * normalize);
bluc = round(bluc * normalize);
*/
// Draw sine curves
if (x>0) {
stroke(255, 0, 0);
line (ox+xOrigo, yOrigo-oldr, x+xOrigo, yOrigo-redc);
stroke(0, 128, 0);
line (ox+xOrigo, yOrigo-oldg, x+xOrigo, yOrigo-grnc);
stroke(0, 0, 255);
line (ox+xOrigo, yOrigo-oldb, x+xOrigo, yOrigo-bluc);
}
// show spectrum
stroke(redc, grnc, bluc);
line (x+xOrigo, yOrigo+10, x+xOrigo, yOrigo+50);
ox = x;
oldr = redc;
oldg = grnc;
oldb = bluc;
}
}
void draw() {
}