Older Version
Newer Version
cogburn
May 23, 2012
Spectral Lines
I would like to get things off to a good start by posting some code to a program I just finished today involving the spectral lines produced by quantum electron transitions. The program calculates wavelengths of the Balmer lines of the hydrogen spectrum and shows the lines as they would appear in a spectroscope. Please feel free to use this and any other programs you find here.
Now I can't take credit for all of this code- the Liberty Basic Forum folks were invaluable in helping me over the rough spots, especially with the second program that gives students practice in measuring with a metric ruler. I recommend a visit over there to learn a great deal from experienced people.
Also- don't be shy about posting you own code or maybe a program you have been thinking about writing. This is a place for sharing information and ideas.--Scott
[[code format="lb"]] code
I would like to get things off to a good start by posting some code to a program I just finished today involving the spectral lines produced by quantum electron transitions. The program calculates wavelengths of the Balmer lines of the hydrogen spectrum and shows the lines as they would appear in a spectroscope. Please feel free to use this and any other programs you find here.
Now I can't take credit for all of this code- the Liberty Basic Forum folks were invaluable in helping me over the rough spots, especially with the second program that gives students practice in measuring with a metric ruler. I recommend a visit over there to learn a great deal from experienced people.
Also- don't be shy about posting you own code or maybe a program you have been thinking about writing. This is a place for sharing information and ideas.--Scott
- I modified this program today- 11/24/2011-to make it easier to use ( I think). Anyway it now prevents users from using out of range numbers.
[[code]]
'**********************************************************
'This program uses the Rydberg modification of the Balmer
'formula to calculate the wavelength of light produced when
'an electron returns to energy level 2 from one of 5 higher
'energy levels. It also simulates the color of the light in the
'hydrogen spectrum produced when this transition occurs.
'***********************************************************
'Window set ups
''***********************************************************
nomainwin
array$(3) = "3"
array$(4) = "4"
array$(5) = "5"
array$(6) = "6"
array$(7) = "7"
WindowWidth = 640
WindowHeight = 660
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = int((DisplayHeight-WindowHeight)/2)
listbox #w.g.list1, array$( ),[entered], 10, 520, 50, 32
graphicbox #w.g, 10, 10, 600, 500
statictext #w.s, "Select the initial energy level by double clicking the menu choice." , 10, 560, 550, 30
statictext #w.s, "In each case, the spectral line will represent the energy transition back to energy level 2." , 10, 580, 550, 30
textbox #w.tb2, 20,100,300,32
textbox #w.tb3, 20,150,300,32
textbox #w.tb4, 20,200,300,32
open "Hydrogen Emission Spectra" for window as #w
#w, "trapclose [quit]"
'*****************************************************
'Draw wavelength ruler and make marks
'*****************************************************
#w.g, "goto 50 400"
#w.g, "down"
#w.g, "goto 50 450"
#w.g, "goto 550 450"
#w.g, "goto 550 400"
#w.g, "flush"
#w.g, "goto 50 400"
x = 50
y = 400
z = 425
#w.g, "up"
#w.g, "goto ";x;" ";z
for i = 1 to 9
x = x + 50
#w.g, "goto ";x;" ";y
#w.g, "down"
#w.g, "goto ";x;" ";z
#w.g, "up"
next i
x = 50
y = 400
z = 410
#w.g, "up"
#w.g, "goto ";x;" ";z
for i = 1 to 100
x = x + 5
#w.g, "goto ";x;" ";y
#w.g, "down"
#w.g, "goto ";x;" ";z
#w.g, "up"
next i
x = 50
y = 400
z = 425
for j = 1 to 19
x = x + 25
#w.g, "goto ";x;" ";y
#w.g, "down"
#w.g, "goto ";x;" ";z
#w.g, "up"
next j
'**************************************************
'print the wavelengths in nm
'**************************************************
x = 95
y = 430
d = 300
#w.g,"down"
#w.g, "place ";x;" ";y
print #w.g, "\";d
for j = 1 to 8
d = d+50
x = x + 50
#w.g, "place ";x;" ";y
print #w.g, "\";d
next j
#w.g, "flush"
#w.g, "up"
#w.g, "goto 50 400"
#w.g, "down"
x = 550:y = 350
print #w.g, "backcolor white"
print #w.g, "color white"
print #w.g, "boxfilled ";x;" ";y
#w.g, "goto 50 400"
#w.g, "down"
x = 550
print #w.g, "backcolor black"
print #w.g, "box ";x;" ";y
print #w.g, "boxfilled ";x;" ";y
print #w.g,"flush"
wait
'**************************************************
'Show emission line in response to wavelength entry
'**************************************************
[entered]
print #w.g.list1, "selection?"
input #w.g.list1, selected$
n =val(selected$)
'****************************************************
'calculation
'****************************************************
c = (1/4)-(1/n^2)
L = 1/(1.097e7 *c)
i = 9
rounded = int(L*10^i +0.5) / 10^i
wavelength = rounded * 1e9
print #w.tb2, "1.097e7 * [1/2^2 - 1/";n^2;"] = 1/lambda"
print #w.tb3, "lambda = 1/(1.907e7 * ";c;")"
print #w.tb4, "wavelength = ";wavelength;" nm"
select case wavelength
case 656
#w.g,"up"
#w.g,"color red"
#w.g,"backcolor red"
#w.g, "size 5"
#w.g,"goto 457 355"'355 use for all
#w.g,"down"
#w.g,"goto 457 394"'394 use for all
#w.g,"flush"
wait
case 486
#w.g,"up"
#w.g,"color cyan"
#w.g,"backcolor cyan"
#w.g, "size 5"
#w.g,"goto 286 355"'355 use for all
#w.g,"down"
#w.g,"goto 286 394"'394 use for all
#w.g,"flush"
wait
case 434
#w.g,"up"
#w.g,"color 130 100 215"
#w.g,"backcolor 130 100 215"
#w.g, "size 5"
#w.g,"goto 235 355"'355 use for all
#w.g,"down"
#w.g,"goto 235 394"'394 use for all
#w.g,"flush"
wait
case 410
#w.g,"up"
#w.g,"color 110 10 180"
#w.g,"backcolor 110 10 180"
#w.g, "size 5"
#w.g,"goto 210 355"'355 use for all
#w.g,"down"
#w.g,"goto 210 394"'394 use for all
#w.g,"flush"
wait
case 397
#w.g,"up"
#w.g,"color 70 0 120"
#w.g,"backcolor 70 0 120"
#w.g, "size 5"
#w.g,"goto 200 355"'355 use for all
#w.g,"down"
#w.g,"goto 200 394"'394 use for all
#w.g,"flush"
wait
case else
wait
end select
wait
[quit]
close #w
end