Skip to content

Instantly share code, notes, and snippets.

@r-lyeh-archived
Created March 17, 2016 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-lyeh-archived/eb94de07b5fcb3b4baaf to your computer and use it in GitHub Desktop.
Save r-lyeh-archived/eb94de07b5fcb3b4baaf to your computer and use it in GitHub Desktop.
// [ref] https://www.niksula.hut.fi/~hkankaan/Homepages/changeable%20colors.html
// This is my example picture. Now I want to make that red ball to be brown, green to be yellow and blue to be white. Notice that this picture also has antialiased lines.
//slide(x,y) means an array slide(from color,to color)
//these three lines make channel 0 (red channel) brown
//(172 red, 108 green and 48 blue equals brown)
slide(0,0) = 172
slide(0,1) = 108
slide(0,2) = 48
//these three lines make channel 1 (green channel) yellow
//(256 red, 256 green and 0 blue)
slide(1,0) = 256
slide(1,1) = 256
slide(1,2) = 0
//try to quess what these lines do ;)
slide(2,0) = 256
slide(2,1) = 256
slide(2,2) = 256
//now lets convert red channel to brown, like we want
col(0, 0) = red * slide(0, 0) / 256
col(0, 1) = red * slide(0, 1) / 256
col(0, 2) = red * slide(0, 2) / 256
//green to yellow
col(1, 0) = green * slide(1, 0) / 256
col(1, 1) = green * slide(1, 1) / 256
col(1, 2) = green * slide(1, 2) / 256
//blue to white
col(2, 0) = blue * slide(2, 0) / 256
col(2, 1) = blue * slide(2, 1) / 256
col(2, 2) = blue * slide(2, 2) / 256
//sqrt=square root function. The following lines just take all the
//red, green and blue we now got and combine a new color.
#if accurate
new_red = sqrt(col(0, 0)^2 + col(1, 0)^2 + col(2, 0)^2)
new_green = sqrt(col(0, 1)^2 + col(1, 1)^2 + col(2, 1)^2)
new_blue = sqrt(col(0, 2)^2 + col(1, 2)^2 + col(2, 2)^2)
#else
new_red = col(0, 0) + col(1, 0) + col(2, 0)
new_green = col(0, 1) + col(1, 1) + col(2, 1)
new_blue = col(0, 2)+ col(1, 2) + col(2, 2)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment