Microsoft Small Basic

Program Listing: GNM423-0
string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero."

gh = 420 - 17
If Text.StartsWith(Program.Directory, "http://smallbasic.com") Then
gh = 420 - 25
EndIf

'Tally the letters used
For i = 1 To Text.GetLength(string)
lowerCaseCharacterCode = Text.GetCharacterCode(Text.ConvertToLowerCase(Text.GetSubText(string, i, 1)))
If lowerCaseCharacterCode >= Text.GetCharacterCode("a") And lowerCaseCharacterCode <= Text.GetCharacterCode("z") Then
tally[lowerCaseCharacterCode] = tally[lowerCaseCharacterCode] + 1
max = Math.Max(max, tally[lowerCaseCharacterCode])
EndIf
EndFor

'Calibrate
GraphicsWindow.BrushColor = "#2B2828"
For y = 0 To gh Step gh /5 *2
GraphicsWindow.FillRectangle(0, y, GraphicsWindow.Width, gh /5)
EndFor

GraphicsWindow.BrushColor = "silver"
For i = 1 To 5
ref = Shapes.AddText(Math.Round(max - (i-1) * max /5))
Shapes.Move(ref, 0, gh /5 *(i-1))
EndFor

'Draw Tally from a to z
GraphicsWindow.PenWidth = 15
GraphicsWindow.PenColor = "DodgerBlue"
For i = Text.GetCharacterCode("a") To Text.GetCharacterCode("z")
If tally[i] > 0 Then
j = j + 1
x = (GraphicsWindow.PenWidth * (j-1)) + GraphicsWindow.PenWidth /3 *j + GraphicsWindow.PenWidth/2 +15
y = gh - tally[i] / max * gh
GraphicsWindow.DrawLine(x, y, x, gh)
GraphicsWindow.DrawText(x-5 , gh, Text.GetCharacter(i)) 'fudge in x offset
sum = sum + tally[i]
EndIf
EndFor

GraphicsWindow.CanResize = 0
GraphicsWindow.Width = (GraphicsWindow.PenWidth * (j)) + GraphicsWindow.PenWidth /3 *(j+1) + 15
GraphicsWindow.Height = 420
GraphicsWindow.BackgroundColor = "black"
GraphicsWindow.Title = "Letter Frequency. [Count = " + sum + "]"