Microsoft Small Basic

Program Listing: GCN044
' Pascal's Triangle
' Copyright © 2018 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Pascal's Triangle"
level = 12
Init()
For j = 1 To level
_x = x
For i = 1 To j
GraphicsWindow.DrawEllipse(x - r, y - r, 2 * r, 2 * r)
If (i = 1) Or (i = j) Then
p[j][i] = 1
Else
p[j][i] = p[j - 1][i - 1] + p[j - 1][i]
EndIf
h = fs * 1.1
w = Text.GetLength(p[j][i]) * fs * 0.6
GraphicsWindow.DrawText(x - w / 2, y - h / 2, p[j][i])
x = x + 2 * dx
EndFor
x = _x - dx
y = y + dy
EndFor

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
dy = gh / (level + 1)
dx = dy / Math.SquareRoot(3)
y = dy
x = gw / 2
r = dy * 0.5
fs = r * 0.8
GraphicsWindow.PenColor = "Cyan"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = fs
GraphicsWindow.FontName = "Trebuchet MS"
EndSub