Microsoft Small Basic

Program Listing: XVH564-0

met="false

Controls.AddButton("next>" 5 GraphicsWindow.Height-25)
Controls.ButtonClicked=bcc
bccl="false
init()
While bccl="false
Program.Delay(22)
EndWhile
met="true
GraphicsWindow.Clear()
init()

sub bcc
bccl="true
EndSub

Sub init
bg = "LightGray"
pc = "lightgreen"
If met Then
GraphicsWindow.Title = "Molecular Structure of Methane"
bb=LDShapes.BrushGradient("1=skyblue;2=darkblue" "DD")
Else
GraphicsWindow.Title = "Molecular Structure of CFC-11 (Chlorofluorocarbon)"
bb=LDShapes.BrushGradient("1=lightgray;2=#222222" "DD")
EndIf

ldGraphicsWindow.BackgroundBrush(bb)
' size: Van der Waals radius / 2 [pm]
' 1: single-bond covalent radius [pm]
' 2: double-bond covalent radius [pm]
' 3: triple-bond covalent radius [pm]
atom["H"] = "color=White;size=55;1=32;cl2=gray
atom["C"] = "color=gray;size=85;1=75;2=67;3=60;c2=black
atom["O"] = "color=#EE0000;size=76;1=63;2=57;3=53
atom["F"] = "color=YellowGreen;size=73.5;1=64;2=59;3=53;c2=#00aa00
atom["Cl"] = "color=LimeGreen;size=87.5;1=99;2=95;3=93;c2=darkgreen
root2 = Math.SquareRoot(2)
root3 = Math.SquareRoot(3)
mol = "CCl_3F"
If met Then
mol="CH_4
atom["cl"]["color"]="white
atom["cl"]["c2"]="gray
atom["f"]["color"]="white
atom["f"]["c2"]="gray
atom["f"]["size"]=55
atom["cl"]["size"]=55
EndIf
DrawMolecularName()
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
_size = atom["Cl"]["size"]
size = atom["C"]["size"]
n = 1
distance = atom["C"][n] + atom["Cl"][n]
gap = distance - size / 2 - _size / 2
d1 = size / 2
d2 = size / 2 + gap
opt = ""
cx = gw / 2
cy = gh / 2
c = 2 / 3 * root2
s = 1 / 3
' draw line (1)
x1 = cx
y1 = cy - d1
x2 = cx
y2 = cy - (atom["C"][n] + atom["F"][n])
DrawLine()
' draw F (1)
at = atom["F"]

ox = cx
oy = y2
FillCircle()
' draw Cl (2)
at = atom["Cl"]

ox = cx - distance * root3 / 2 * c
oy = cy + distance * s
FillCircle()
' draw line (2)
x1 = cx - d1 * root3 / 2 * c
y1 = cy + d1 * s
x2 = cx - d2 * root3 / 2 * c
y2 = cy + d2 * s
n = 1
DrawLine()
' draw Cl (3)
ox = cx + distance * root3 / 2 * c
FillCircle()
' draw line (3)
x1 = cx + d1 * root3 / 2 * c
y1 = cy + d1 * s
x2 = cx + d2 * root3 / 2 * c
y2 = cy + d2 * s
n = 1
DrawLine()
' draw C
at = atom["C"]
ox = cx
oy = cy
FillCircle()
' draw Cl (4)
at = atom["Cl"]

ox = cx
oy = cy + distance * s
FillCircle()
EndSub

Sub DrawLine
GraphicsWindow.PenColor = pc
If n = 2 Then
GraphicsWindow.PenWidth = 12
GraphicsWindow.DrawLine(x1, y1, x2, y2)
GraphicsWindow.PenColor = bg
EndIf
GraphicsWindow.PenWidth = 6
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndSub

Sub DrawMolecularName
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.BrushColor = "Black"
x = 30
For p = 1 To Text.GetLength(mol)
c = Text.GetSubText(mol, p, 1)
If c = "_" Then
y = 35
p = p + 1
fs = 20
c = Text.GetSubText(mol, p, 1)
Else
y = 20
fs = 30
EndIf
GraphicsWindow.FontSize = fs
GraphicsWindow.DrawText(x, y, c)
x = x + fs * 0.7
EndFor
EndSub

Sub FillCircle
size=at["size"]
bc=at["color"]
c2=at["c2"]

GraphicsWindow.BrushColor = bc
bb=LDShapes.BrushGradient("1="+bc+";2="+c2 "")
LDShapes.BrushEllipse(bb ox - size / 2, oy - size / 2 size size)

If opt <> "" Then
GraphicsWindow.FontSize = 35
GraphicsWindow.BrushColor = pc
GraphicsWindow.DrawText(ox + size / 2, oy - size / 2, opt)
EndIf
EndSub