Microsoft Small Basic

Program Listing: QGK077-0
' Line with Character in TextWindow
' Copyright © 2015-2017 Nonki Takahashi. The MIT License.
' Last update 2017-03-13
' Program ID QGK077-0

param = "char=A;col1=0;row1=0;col2=79;row2=24;color=Cyan;"
TW_DrawLineWithChar()
param = "char=B;col1=0;row1=24;col2=79;row2=0;color=Yellow;"
TW_DrawLineWithChar()
param = "char=C;col1=0;row1=12;col2=79;row2=12;color=Green;"
TW_DrawLineWithChar()
param = "char=D;col1=40;row1=0;col2=40;row2=24;color=Red;"
TW_DrawLineWithChar()
TextWindow.CursorLeft = 0
TextWindow.CursorTop = 0
TextWindow.ForegroundColor = "Gray"

Sub TW_DrawLineWithChar
' TextWindow | Draw line with character
' param["char"] - character
' param["col1"] - column of the first cell
' param["row1"] - row of the first cell
' param["col2"] - column of the second cell
' param["row2"] - row of the second cell
' param["color"] - color of the character
TextWindow.ForegroundColor = param["color"]
width = Math.Abs(param["col2"] - param["col1"])
height = Math.Abs(param["row2"] - param["row1"])
If width < height Then
flipColRow = "True"
xchg = param["col1"]
param["col1"] = param["row1"]
param["row1"] = xchg
xchg = param["col2"]
param["col2"] = param["row2"]
param["row2"] = xchg
Else
flipColRow = "False"
EndIf
If param["row1"] <= param["row2"] Then
startRow = param["row1"]
endRow = param["row2"]
Else
startRow = param["row2"]
endRow = param["row1"]
EndIf
If param["col1"] <= param["col2"] Then
dirCol = 1
Else
dirCol = -1
EndIf
row1c = param["row1"] + 0.5
row2c = param["row2"] + 0.5
For col = param["col1"] To param["col2"] Step dirCol
If row1c = row2c Then
row = row1c
Else
row = Math.Floor(row1c + col / width * (row2c - row1c))
EndIf
If flipColRow Then
TextWindow.CursorLeft = row
TextWindow.CursorTop = col
Else
TextWindow.CursorLeft = col
TextWindow.CursorTop = row
EndIF
TextWindow.Write(param["char"])
EndFor
EndSub