3 comments on “Spectrum-Generating Color Function Using Sine Waves

  1. Here is some javascript that I use based on this article.
    n=amp; // This is some value from 2D array
    m=maxVal; // This is maximum value in 2D array, for n divided by n normalization below

    let a=5*3.14/3*n/m+3.14/2;
    let r=Math.sin(a) * 192 + 128;
    let g=Math.sin(a – 2*3.14/3) * 192 + 128;
    let b=Math.sin(a – 4*3.14/3) * 192 + 128;

    if (r<0) {r=0;}
    if (g<0) {g=0;}
    if (b255) {r=255;}
    if (g>255) {g=255;}
    if (b>255) {b=255;}

    setPixel(myImage,i,myImage.height-1-k,b,g,r);

  2. Hi, I’ve tried to use your function, but there is a “y” not defined on lines 3,5,7. I’ve tried to substitute respectively with r,g,b (reading the article it seemed to me that should be the idea!), but I only get Red, Green and Blue colors using m = 10000 and ciclyng trough different values of n (from 0 to 10000)… could you help me?
    thank you in advance!

Leave a Reply