Microsoft Small Basic

Program Listing: WGZ319
'Area of a triangle
TextWindow.Write("enter the value of the base of the triangle: ")
base = TextWindow.ReadNumber()
TextWindow.Write("enter the value of the height of the triangle: ")
height = TextWindow.ReadNumber()
area = (base * height) / 2
TextWindow.WriteLine("The area is " + Area)

cm = 24 ' [px/cm]
size = 12 ' [cm]
GraphicsWindow.Width = cm * size
GraphicsWindow.Height = cm * size
GraphicsWindow.Top = TextWindow.Top + 150
GraphicsWindow.Left = TextWindow.Left + 50
GraphicsWindow.BackgroundColor = "LightGray"
DrawGrid()
DrawTriangle()

Sub DrawGrid
GraphicsWindow.PenColor = "DimGray"
For x = 0 To cm * size Step cm
GraphicsWindow.DrawLine(x, 0, x, cm * size)
EndFor
For y = 0 To cm * size Step cm
GraphicsWindow.DrawLine(0, y, cm * size, y)
EndFor
EndSub

Sub DrawTriangle
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "MediumSeaGreen"
k = 0.3 ' 0 <= k <= 1
pxBase = base * cm
pxHeight = height * cm
x1 = pxBase * k
y1 = 0
x2 = pxBase
y2 = pxHeight
x3 = 0
y3 = y2
triangle = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
Shapes.Move(triangle, cm, cm)
EndSub