// spectre //J.roussel //Octobre 2008 //Dernière mise à jour 2019-02-14 float IR,IG,IB; int freq; void setup() { size(500,100); textSize(14); // set the font size to something big frameRate(10); textAlign(CORNER); smooth(); colorMode(RGB,1.0); } void draw() { background(2); for(int lambda=380;lambda<780;lambda++){ lambdaToRgb(lambda); stroke(IR,IG,IB); line(lambda-330,25,lambda-330,75); } if( (mouseX>50 && mouseX<450) && (mouseY>25 && mouseY<75)) { stroke(1); fill(1); line(mouseX,25,mouseX,80); fill(0); text("\u03BB = "+(mouseX+330)+" nm",mouseX,93); freq=int(300000/(mouseX+330)); text("\u03BD = "+freq+" THz",mouseX,17); } } void lambdaToRgb(int x) { float R=1;float G=1;float B=1;float sat=1; if(x<440 && x>=380){ R=(440.-x)/60;G=0;B=1.; } if(x<490 && x>=440){ R=0;G=(x-440.)/50.;B=1.; } if(x<510 && x>=490){ R=0;G=1.;B=(510.-x)/20.; } if(x<580 && x>=510){ R=(x-510.)/70.;G=1.;B=0; } if(x<645 && x>=580){ R=1;G=(645.-x)/65.;B=0; } if(x<780 && x>=645){ R=1.;G=0;B=0; } if(x>700){ sat=0.3+0.7*(780.-x)/80.; } if(x<420){ sat=0.3+0.7*(x-380.)/40.; } IR=(sat*R);IG=(sat*G);IB=(sat*B); }