Open vagaruy opened 7 years ago
'Given a temperature (in Kelvin), generate the RGB equivalent of an ideal black body ' NOTE: the mathematical formula used in this routine is NOT STANDARD. I wrote it myself using self-calculated regression equations based ' off the raw data on blackbody radiation provided at http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html ' Because of that, I can't guarantee great precision - but the function works well enough for photo-manipulation purposes.
Private Sub GetRGBfromTemperature(ByRef r As Long, ByRef g As Long, ByRef b As Long, ByVal tmpKelvin As Long)
Dim tmpCalc As Double
'Temperature must fall between 1000 and 40000 degrees
If (tmpKelvin < 1000) Then tmpKelvin = 1000
If (tmpKelvin > 40000) Then tmpKelvin = 40000
'All calculations require tmpKelvin \ 100, so only do the conversion once
tmpKelvin = tmpKelvin \ 100
'Calculate each color in turn
'First: red
If (tmpKelvin <= 66) Then
r = 255
Else
tmpCalc = tmpKelvin - 55
r = 351.976905668057 + 0.114206453784165 * tmpCalc + -40.2536630933213 * Log(tmpCalc)
If (r < 0) Then r = 0
If (r > 255) Then r = 255
End If
'Second: green
If (tmpKelvin <= 66) Then
tmpCalc = tmpKelvin - 2
g = -155.254855627092 + -0.445969504695791 * tmpCalc + 104.492161993939 * Log(tmpCalc)
If (g < 0) Then g = 0
If (g > 255) Then g = 255
Else
tmpCalc = tmpKelvin - 50
g = 325.449412571197 + 7.94345653666234E-02 * tmpCalc + -28.0852963507957 * Log(tmpCalc)
If (g < 0) Then g = 0
If (g > 255) Then g = 255
End If
'Third: blue
If (tmpKelvin >= 66) Then
b = 255
ElseIf (tmpKelvin <= 19) Then
b = 0
Else
tmpCalc = tmpKelvin - 10
b = -254.769351841209 + 0.827409606400739 * tmpCalc + 115.679944010661 * Log(tmpCalc)
If (b < 0) Then b = 0
If (b > 255) Then b = 255
End If
End Sub
Intensity Equations at different times of the day and weather characters. Can be used to get some accurate information on how to map the intensity of the RGB light at different times of the day. SunMoonLuminosity.pdf
Create a PWM wave form for simulating sunrise, daytime and night time based on current moon conditions and the fog in the a