ghost town inquisition
hi everyone, i am trying to figure out how to map the color of an rgb led to the "direction traveled in degrees" info from the gps.
the primary colors of red yellow and blue are all 120 degrees apart on the color wheel but i have a red GREEN and blue led. Red and green are 180 degrees apart.
Red is 0 degrees = Red 1 Green 0 Blue 0
orange is 60 degrees = Red 0.6 Green 0.3 Blue 0
Yellow is 120 degrees = Red 0.3 Green 0.6 Blue 0
green is 180 degrees = Red 0 Green 1 Blue 0
Blue is 240 degrees = Red 0 Green 0 Blue 1
purple is 300 degrees = Red 0.5 Green 0 Blue 0.5
i would think i could have 6*30=180 colors instead of just six; one for every other possible direction in whole number degrees.
is there an easy way to calculate the recipe for my 180 PWM colors?
Michael:
Sounds like you could just use the weighted average for each of the parts independently. E.g., for 30 degrees (halfway between 0 and 60):
red = .5 * 1 = .5
green = blue = .5 * 0
For 75 degrees (1/4 between 60 and 120):
red = ((.3 - .6) * (1/4)) + .6 = .525
green = ((.6 - .3) * (1/4)) + .3 = .375
blue = 0
In general:
1) Figure out which span you are in. For example if you are computing the color for 75 degrees (lets call that 'a') , it falls in the 60-120 span:
S0 = 60deg, S1 = 120deg
2) Compute 'how far along' you are through that span as a fraction:
Sf = (a - S0) / (S1 - S0)
Sf = (75 - 60) / (120 - 60) = 15/60 = .25
3) For each of the color components, apply that 'distance' to the specific value range:
R = R0 + (Sf * (R1 - R0)) = .6 + (.25 * (.3 - .6)) = .6 + (-.075) = .525
G = G0 + (Sf * (G1 - G0))
B = B0 + (Sf * (B1 - B0))
Hope it helps
Post new comment