Microsoft Small Basic

Program Listing:
Embed this in your website
' Molecular Structure of Carbon Dioxide
' Version 0.2
' Copyright © 2019 Nonki Takahashi. The MIT License.
' Last update 2019-11-16
' Program ID KCN639-0

GraphicsWindow.Title = "Molecular Structure of Carbon Dioxide"
bg = "LightGray"
pc = "DimGray"
GraphicsWindow.BackgroundColor = bg
atom["C"] = "color=Black;size=150;"
atom["O"] = "color=#EE0000;size=100;"
atom["H"] = "color=White;size=50;"
gap = 20
a = 180  ' [degree]
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
mol = "CO_2"
DrawMolecularName()
' draw line (1)
x1 = gw / 2
y1 = gh / 2
size = atom["C"]["size"]
_size = size
size = atom["O"]["size"]
r = _size / 2 + size / 2 + gap
_ah = Math.GetRadians(a / 2)
x2 = x1 - r * Math.Sin(_ah)
y2 = y1 + r * Math.Cos(_ah)
n = 2
DrawLine()
' draw O (1)
ox = x2
oy = y2
bc = atom["O"]["color"]
FillCircle()
' draw line (2)
x2 = x1 + r * Math.Sin(_ah)
DrawLine()
' draw O (2)
ox = x2
FillCircle()
' draw C
ox = x1
oy = y1
size = atom["C"]["size"]
bc = atom["C"]["color"]
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)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.