8968d35b5639ad14c39a3a1b697e4d984d124df0 ceisenhart Fri Oct 9 09:54:01 2015 -0700 Adding rainbow.h and rainbow.c, I modified these files a very long time ago for the expMatrixToJson program, giving them a new function diff --git src/lib/rainbow.c src/lib/rainbow.c index 95e8021..5465b23 100644 --- src/lib/rainbow.c +++ src/lib/rainbow.c @@ -95,30 +95,66 @@ {174,223,255}, {174,207,255}, {174,191,255}, {174,174,255}, {191,174,255}, {207,174,255}, {223,174,255}, {239,174,255}, {255,174,255}, {255,174,239}, {255,174,223}, {255,174,207}, {255,174,191}, }; + +static struct rgbColor whiteToBlackRainbowTable[30] = { +/* This is a rainbow from white to black. There are no colors, only varying + * shades of grey. It is good for displays that are not meant to draw attention. */ + {255,255,255}, + {247,247,247}, + {238,238,238}, + {230,230,230}, + {221,221,221}, + {213,213,213}, + {204,204,204}, + {196,196,196}, + {187,187,187}, + {179,179,179}, + {170,170,170}, + {162,162,162}, + {153,153,153}, + {145,145,145}, + {136,136,136}, + {128,128,128}, + {119,119,119}, + {111,111,111}, + {102,102,102}, + {93,93,93}, + {85,85,85}, + {76,76,76}, + {68,68,68}, + {59,59,59}, + {50,50,50}, + {42,42,42}, + {33,33,33}, + {25,25,25}, + {16,16,16}, + {0,0,0}, +}; + static struct rgbColor interpolatedHue(struct rgbColor *table, int tableSize, double pos) /* Given pos, a number between 0 and 1, return interpolated color, doing interpolation * between first and last color for numbers close to 1. */ { double wrappedPos = pos - floor(pos); /* Make it so numbers higher than 1 keep circling rainbow */ double scaledPos = tableSize * wrappedPos; double startSlot = floor(scaledPos); double endFactor = scaledPos - startSlot; double startFactor = 1.0 - endFactor; int startIx = startSlot; int endIx = startIx + 1; if (endIx == tableSize) endIx = 0; struct rgbColor *start = table+startIx; @@ -139,15 +175,21 @@ struct rgbColor lightRainbowAtPos(double pos) /* Given pos, a number between 0 and 1, return a lightish rainbow rgbColor * where 0 maps to red, 0.1 is orange, and 0.9 is violet and 1.0 is back to red */ { return interpolatedHue(lightRainbowTable, ArraySize(lightRainbowTable), pos); } struct rgbColor saturatedRainbowAtPos(double pos) /* Given pos, a number between 0 and 1, return a saturated rainbow rgbColor * where 0 maps to red, 0.1 is orange, and 0.9 is violet and 1.0 is back to red */ { return interpolatedHue(saturatedRainbowTable, ArraySize(saturatedRainbowTable), pos); } +struct rgbColor whiteToBlackRainbowAtPos(double pos) +/* Given pos, a number between 0 and 1, return a blackToWhite rainbow rgbColor + * where 0 maps to white, 0.1 is grey, and 1 is black. */ +{ +return interpolatedHue(whiteToBlackRainbowTable, ArraySize(whiteToBlackRainbowTable), pos); +}