Microsoft Small Basic

Program Listing: VGR488
' Wavelength vs Refractive Index
' Copyright © 2017 Nonki Takahashi. The MIT License.

' Reference
' [1] http://www.hoya-opticalworld.com/english/technical/002.html
' [2] http://smallbasic.com/program/?PGK814

GraphicsWindow.Title = "Wavelength vs Refractive Index"
InitColor()
ni = Array.GetItemCount(color)
index = Array.GetAllIndices(color)
DrawGrid()
glass = "C7"
Plot()
glass = "F2"
Plot()

Sub DrawGrid
GraphicsWindow.PenColor = "LightGray"
GraphicsWindow.BrushColor = "Gray"
λ = 400
n = 1.5
Map()
x400 = x
y1_5 = y
n = 1.7
For λ = 400 To 700 Step 50
Map()
GraphicsWindow.DrawLine(x, y, x, y1_5)
GraphicsWindow.DrawText(x - 10, y1_5 + 10, λ)
EndFor
GraphicsWindow.DrawText(x + 20, y1_5 + 10, "λ[nm]")
λ = 700
For n = 1.5 To 1.7 Step 0.05
Map()
GraphicsWindow.DrawLine(x400, y, x, y)
GraphicsWindow.DrawText(x400 - 30, y - 10, n)
EndFor
GraphicsWindow.DrawText(x400 - 30, y - 30, "n")
EndSub

Sub InitColor
'Wavelength to Color
color[404] = "sp=h;c=#0800FF;C7=1.52532;F2=1.65070;"
color[436] = "sp=g;c=#0000FF;C7=1.52155;F2=1.64206;"
' color[480] = "sp=F';c=#0074FF;C7=1.51747;F2=1.63312;"
color[486] = "sp=F;c=#00A6FF;C7=1.51699;F2=1.63210;"
color[546] = "sp=e;c=#00FE00;C7=1.51314;F2=1.62409;"
color[588] = "sp=d;c=#FF5A00;C7=1.51112;F2=1.62004;"
' color[590] = "sp=D;c=#FF5000;C7=1.51105;F2=1.61989;"
color[632] = "sp=632.8;c=#FF0800;C7=1.50934;F2=1.61655;"
' color[644] = "sp=C';c=#FF0400;C7=1.50895;F2=1.61581;"
color[656] = "sp=C;c=#FF0200;C7=1.50854;F2=1.61502;"
EndSub

Sub Map
' param λ, n
' return x, y
x = λ - 220
y = 300 - (n - 1.5) * 1000
EndSub

Sub Plot
GraphicsWindow.PenColor = "Black"
For i = 1 To ni
λ = index[i]
clr = color[λ]
n = clr[glass]
Map()
If 1 < i Then
GraphicsWindow.PenWidth = 2
GraphicsWindow.DrawLine(x, y, xLast, yLast)
EndIf
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = clr["c"]
dot = Shapes.AddEllipse(4, 4)
Shapes.Move(dot, x - 2, y - 2)
xLast = x
yLast = y
EndFor
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(x, y - 20, glass)
EndSub