Microsoft Small Basic

Program Listing:
Embed this in your website
' Molecular Structure of CFC-11
' Version 0.3
' Copyright © 2019 Nonki Takahashi. The MIT License.
' Last update 2019-11-20

GraphicsWindow.Title = "Molecular Structure of CFC-11 (Chlorofluorocarbon)"
bg = "LightGray"
pc = "DimGray"
GraphicsWindow.BackgroundColor = bg
' 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;"
atom["C"] = "color=Black;size=85;1=75;2=67;3=60;"
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;"
atom["Cl"] = "color=LimeGreen;size=87.5;1=99;2=95;3=93;"
root2 = Math.SquareRoot(2)
root3 = Math.SquareRoot(3)
mol = "CCl_3F"
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)
bc = atom["F"]["color"]
size = atom["F"]["size"]
ox = cx
oy = y2
FillCircle()
' draw Cl (2)
bc = atom["Cl"]["color"]
size = _size
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
size = atom["C"]["size"]
bc = atom["C"]["color"]
ox = cx
oy = cy
FillCircle()
' draw Cl (4)
bc = atom["Cl"]["color"]
size = _size
ox = cx
oy = cy + distance * s
FillCircle()

Sub DrawLine
  GraphicsWindow.PenColor = pc
  If n = 2 Then
    GraphicsWindow.PenWidth = 12
    GraphicsWindow.DrawLine(x1, y1, x2, y2)
    GraphicsWindow.PenColor = bg
  EndIf
  GraphicsWindow.PenWidth = 4
  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
  GraphicsWindow.BrushColor = bc
  GraphicsWindow.FillEllipse(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
Copyright (c) Microsoft Corporation. All rights reserved.