The Ultra-violet Catastrophe.

I found an old printout of code I wrote decades ago, when only text output was possible. I converted it to LB and kept getting overflow and underflow errors- the variables and constants are HUGE or TINY, and you have exponentials of already-big numbers to play with. Eventually tamed it by working with logged-variables, so division becomes subtraction. Then had to play to detect the end of the rising curve where it turns back down.

A 'black body' is a 100% efficient radiator of electromagnetic radiation. At temperatures up to 5000K or so,the biggest fraction of energy is observed to be in red and infra red. At temperatures above this, the blue component outweighs the red. Hence 'cool' stars look red; very hot one look blue-white. ( Orion has good examples of each.) Of course, thee brightness to the eye of a 'point' or distant star is affected by its own size and temperature, butt he colour is a direct indicator of the temperature. Good Wikipedia articles for both white dwarfs and red giants.

Unfortunately 19th century theory predicted that the curve should ALWAYS show higher and higher values radiated as the wavelength gets shorter. Only quantum theory showed why we don't have an 'ultra violet catastrophe', where everything in the universe would heat/cool to the same temperature!

You need a physics background to understand it! Relevant maths below!

Despite their smaller size, white dwarfs have higher surface temperatures, often exceeding 100,000 degrees Kelvin, while red giants have cooler surface temperatures, typically around 3,000 to 4,000 degrees Kelvin.

Vertical axis is perceived comparative brightness as seen by a human, whose response ( logarithmic) compreses the scale.

Something 10x as high in temperature radiates at 10000x the power.

THe circle shows the colour a star of the given surface temperature would display to human eye or camera.


Code

I had fun working with such a huge numeric range- luckily pereived brightness is logarithmic, so I can compress the vertical power scale. Another fun bit was finding the maximum.

You'll need the bmp of the visible colours, save from below..

'           *****************************************
'           **                                     **
'           **  powerWavelength08c.bas 13/07/2024  **
'           **                                     **
'           **    tenochtitlanuk  14 July 2024     **
'           **                                     **
'           *****************************************

'   to-dos
'       Add grid    and a background series of ROYGBIV bars         DONE
'       Add demo black body box representing the colour balance     DONE
'       Change colour demonstrator fom box to circle                DONE

'   Despite their smaller size, white dwarfs have higher surface temperatures,
'       often exceeding 100,000 degrees Kelvin, while red giants have cooler
'       surface temperatures, typically around 3,000 to 4,000 degrees Kelvin.

'   Vertical axis is perceived comparative brightness as seen by a human,
'       whose response ( logarithmic) compresaes the scale.

'   Something 10x as high in temperature radiates at 10000x the power.

nomainwin

WindowWidth  = 900
WindowHeight = 700


open "Black Body Radiation- Radiant Power." for graphics_nsb as #wg

#wg "trapclose quit"

#wg "down ; fill 0 0 70"

loadbmp "scr", "spectrum1.bmp"
#wg "drawbmp scr 200 10"

#wg "color lightgray"
for L =0 *1e-9 to 2500 *1e-9 step 250e-9
    x   =int( 60 +L /3000e-9 *1200)
    #wg "line "; x; " 0 "; x; " 700"
next L

for P =0 to 10e11 step 10e10
    x   =int( 650 -int( P /12e8))
    #wg "line 50 "; x; " 1000 "; x
next P

#wg "backcolor black ; up ; goto 660 200 ; down ; circlefilled 90"
#wg "font 8 bold"
#wg "color white "
#wg "up   ; goto 110 663 ; down"
#wg "\Ultra violet"
#wg "up   ; goto 250 663 ; down"
#wg "\VISIBLE"
#wg "up   ; goto 510 663 ; down"
#wg "\Infra red"

#wg "size 1 ; color cyan ; backcolor 0 0 70 ; flush ; up ; font 14 bold"


Pi              =    3.14159265
c               = 3E8               '   velocity of light
h               = 6.62E-34          '   Planck constant
k               =    1.38E-23       '   Boltzmann constant
T               =  300              '   room temperature
'factor          =1.1

C4              =2 *Pi *c^2
K2              =h /k

do
    'print " T = "; T; " K"
    state       =  0
    rising      =  0
    maxPower    = -1e10
    previous    = -1
    Tprinted     =  0

    #wg "color cyan"

    R       =0
    G       =0
    B       =0

    for lambda =110e-9 to 2500e-9 step 1e-9 '   110 nm to 2500 nm.

        logNumerator    =log( C4 *h)

        logDenominator  =log( lambda^5) +log( exp( K2 *c /lambda /T) -1)

        logPower        =logNumerator -logDenominator   '   so =log( power)

        if state =0 then
            #wg "up   ; goto ";   int( 60 +lambda /3000e-9 *1200); " "; 650 -int( 8 *exp( logPower) /12e11)
            state   =1
            #wg "down"
        else
            #wg "set  ";          int( 60 +lambda /3000e-9 *1200); " "; 650 -int( 8 *exp( logPower) /12e11)
        end if

        if ( logPower -previous) <=0 and Tprinted =0 and T >1000 then
            #wg "color white ; backcolor darkblue"
            #wg "up   ; goto 90 ";                                       650 -int( 8 *exp( logPower) /12e11)
            #wg "down"
            #wg "\"; str$( int( T)); " K."
            Tprinted    =1
            #wg "color yellow"
        end if

        select case
            case abs( lambda -550e-9) <=1e-9
                R       =exp( logPower -30)
            case abs( lambda -480e-9) <=1e-9
                G       =exp( logPower -30)
            case abs( lambda -400e-9) <=1e-9
                B       =exp( logPower -30)
        end select

        previous  =logPower

        scan

    next lambda

    T       = T +100

    mx      =max( max( R, G), B)

    col$    =str$( int( 255 *R /mx)) +" " +str$( int( 255 *G /mx)) +" " +str$( int( 255 *B /mx))
    #wg "backcolor "; col$; " ; color black"
    #wg "up ; goto 660 200 ; down ; circlefilled 90"
    #wg "up ; goto 630 190 ; down ; color white ; font 12 bold ; backcolor black"
    #wg "\ "; T; " K. "
    #wg "font 10"

'    print T, R, G, B, col$

loop until T >=10000

#wg "flush"

wait

end

sub quit h$
    close #wg
    end
end sub