Older Version Newer Version

cogburn 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 ** 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 format="lb"]] [[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)nomainwin array$(3) = "3" array$(4) array$(4) = "4" array$(5) array$(5) = "5" array$(6) array$(6) = "6" array$(7) array$(7) = "7" WindowWidthWindowWidth = 640 WindowHeight WindowHeight = 660 UpperLeftX UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY UpperLeftY = int((DisplayHeight-WindowHeight)/2) listbox listbox #w.g.list1, array$( ),[entered], 10, 520, 50, 32 graphicbox graphicbox #w.g, 10, 10, 600, 500 statictext statictext #w.s, "Select the initial energy level by double clicking the menu choice." , 10, 560, 550, 30 statictext statictext #w.s, "In each case, the spectral line will represent the energy transition back to energy level 2." , 10, 580, 550, 30 textbox textbox #w.tb2, 20,100,300,32 textbox textbox #w.tb3, 20,150,300,32 textbox textbox #w.tb4, 20,200,300,32 openopen "Hydrogen Emission Spectra" for window as #w #w, #w, "trapclose [quit]" '***************************************************** 'Draw'Draw wavelength ruler and make marks '***************************************************** '***************************************************** #w.g,#w.g, "goto 50 400" #w.g, #w.g, "down" #w.g, #w.g, "goto 50 450" #w.g, #w.g, "goto 550 450" #w.g, #w.g, "goto 550 400" #w.g, #w.g, "flush" #w.g, #w.g, "goto 50 400" xx = 50 y y = 400 z z = 425 #w.g, #w.g, "up" #w.g, #w.g, "goto ";x;" ";z forfor i = 1 to 9 x x = x + 50 #w.g, #w.g, "goto ";x;" ";y #w.g, #w.g, "down" #w.g, #w.g, "goto ";x;" ";z #w.g, #w.g, "up" next next i x x = 50 y y = 400 z z = 410 #w.g, #w.g, "up" #w.g, #w.g, "goto ";x;" ";z for for i = 1 to 100 x x = x + 5 #w.g, #w.g, "goto ";x;" ";y #w.g, #w.g, "down" #w.g, #w.g, "goto ";x;" ";z #w.g, #w.g, "up" next next i x x = 50 y y = 400 z z = 425 for for j = 1 to 19 x x = x + 25 #w.g, #w.g, "goto ";x;" ";y #w.g, #w.g, "down" #w.g, #w.g, "goto ";x;" ";z #w.g, #w.g, "up" next next j '************************************************** 'print the wavelengths in nm '************************************************** xx = 95 y y = 430 d d = 300 #w.g,"down" #w.g, #w.g,"down" #w.g, "place ";x;" ";y print print #w.g, "\";d forfor j = 1 to 8 d d = d+50 x x = x + 50 #w.g, #w.g, "place ";x;" ";y print print #w.g, "\";d next next j #w.g, #w.g, "flush" #w.g, #w.g, "up" #w.g,#w.g, "goto 50 400" #w.g, #w.g, "down" x x = 550:y = 350 print print #w.g, "backcolor white" print print #w.g, "color white" print print #w.g, "boxfilled ";x;" ";y #w.g, #w.g, "goto 50 400" #w.g, #w.g, "down" x = 550 printprint #w.g, "backcolor black" print print #w.g, "box ";x;" ";y print print #w.g, "boxfilled ";x;" ";y print print #w.g,"flush" wait '************************************************** 'Show wait '************************************************** 'Show emission line in response to wavelength entry '************************************************** [entered] print '************************************************** [entered] print #w.g.list1, "selection?" input input #w.g.list1, selected$ n n =val(selected$) '**************************************************** 'calculation '**************************************************** c '**************************************************** 'calculation '**************************************************** c = (1/4)-(1/n^2) L L = 1/(1.097e7 *c) i i = 9 rounded rounded = int(L*10^i +0.5) / 10^i wavelength wavelength = rounded * 1e9 print print #w.tb2, "1.097e7 * [1/2^2 - 1/";n^2;"] = 1/lambda" print print #w.tb3, "lambda = 1/(1.907e7 * ";c;")" print 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 select case 397 #w.g,"up" #w.g,"color 70 0 120" #w.g,"backcolor 70 0 120" #w.g,wavelength case 656 #w.g,"up" #w.g,"color red" #w.g,"backcolor red" #w.g, "size 5" #w.g,"goto 200 #w.g,"goto 457 355"'355 use for all #w.g,"down" #w.g,"goto 200 #w.g,"down" #w.g,"goto 457 394"'394 use for all #w.g,"flush" wait case else wait end select wait [quit] close #w end #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 [[code]] [[code format="lb"]] [[code]]