styled text outputed
This commit is contained in:
parent
ec084ce210
commit
cfd70851c6
|
@ -1,4 +1,4 @@
|
||||||
import strutils, os, procedures
|
import strutils, os, procedures, terminal
|
||||||
|
|
||||||
var argument: string
|
var argument: string
|
||||||
|
|
||||||
|
@ -12,11 +12,12 @@ if "dot" in args or "d" in args:
|
||||||
elif "cross" in args or "c" in args:
|
elif "cross" in args or "c" in args:
|
||||||
cross()
|
cross()
|
||||||
else:
|
else:
|
||||||
echo "Would you like to preform the dot or cross product?"
|
styledEcho resetStyle, "Would you like to preform the ", styleBright, "dot ", resetStyle, "or ", styleBright, "cross ", resetStyle, "product?"
|
||||||
case toLowerAscii(readLine(stdin)):
|
case toLowerAscii(readLine(stdin)):
|
||||||
of "dot", "d":
|
of "dot", "d":
|
||||||
dot()
|
dot()
|
||||||
of "cross", "c":
|
of "cross", "c":
|
||||||
cross()
|
cross()
|
||||||
else:
|
else:
|
||||||
quit "Invalid operation!", QuitFailure
|
styledEcho fgRed, "Invalid operation!"
|
||||||
|
quit QuitFailure
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import strutils, sequtils
|
import strutils, sequtils, terminal
|
||||||
|
|
||||||
#? validate if user input is of correct type
|
#? validate if user input is of correct type
|
||||||
proc getInt: int =
|
proc getInt: int =
|
||||||
|
@ -6,7 +6,7 @@ proc getInt: int =
|
||||||
try:
|
try:
|
||||||
return parseInt(readline(stdin))
|
return parseInt(readline(stdin))
|
||||||
except:
|
except:
|
||||||
echo "Please enter an integer, try again."
|
styledEcho resetStyle, "Please enter an ", styleBright, "integer, " , resetStyle, "try again."
|
||||||
|
|
||||||
#? validate if user input is of correct type
|
#? validate if user input is of correct type
|
||||||
proc getFloat: float =
|
proc getFloat: float =
|
||||||
|
@ -14,7 +14,7 @@ proc getFloat: float =
|
||||||
try:
|
try:
|
||||||
return parseFloat(readline(stdin))
|
return parseFloat(readline(stdin))
|
||||||
except:
|
except:
|
||||||
echo "Please enter a number, try again."
|
styledEcho resetStyle, "Please enter a ", styleBright, "number, " , resetStyle, "try again."
|
||||||
|
|
||||||
#? prints a matrix to the standard output
|
#? prints a matrix to the standard output
|
||||||
proc printMatrix*(matrix: seq[seq[float]]) =
|
proc printMatrix*(matrix: seq[seq[float]]) =
|
||||||
|
@ -43,7 +43,8 @@ proc calcDot(matrix1: seq[seq[float]], matrix2: seq[seq[float]]): seq[seq[float]
|
||||||
col = col2
|
col = col2
|
||||||
row = row1
|
row = row1
|
||||||
else:
|
else:
|
||||||
quit "Matrix dimensions mismatched, operation invalid!", QuitFailure
|
styledEcho fgRed, "Matrix dimensions mismatched!"
|
||||||
|
quit QuitFailure
|
||||||
|
|
||||||
var matrix = newSeqWith(row, newSeq[float](col))
|
var matrix = newSeqWith(row, newSeq[float](col))
|
||||||
|
|
||||||
|
@ -61,12 +62,12 @@ proc calcCross(vector1: array[3, float], vector2: array[3, float]): array[3, flo
|
||||||
result = [i, j, k]
|
result = [i, j, k]
|
||||||
|
|
||||||
proc dot* =
|
proc dot* =
|
||||||
echo "MATRIX DOT PRODUCT"
|
styledEcho styleBright, "Matrix Dot Product"
|
||||||
|
|
||||||
#? record first matrix
|
#? record first matrix
|
||||||
echo "Enter number of rows in the first matrix:"
|
styledEcho "Enter number of ", styleBright, "rows ", resetStyle, "in the first matrix:"
|
||||||
let r1: int = getInt()
|
let r1: int = getInt()
|
||||||
echo "Enter number of columns in the first matrix:"
|
styledEcho "Enter number of ", styleBright, "columns ", resetStyle, "in the first matrix:"
|
||||||
let c1: int = getInt()
|
let c1: int = getInt()
|
||||||
var m1 = newSeqWith(r1, newSeq[float](c1))
|
var m1 = newSeqWith(r1, newSeq[float](c1))
|
||||||
procedures.fillMatrix(m1, r1, c1)
|
procedures.fillMatrix(m1, r1, c1)
|
||||||
|
@ -74,9 +75,9 @@ proc dot* =
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
#? record second matrix
|
#? record second matrix
|
||||||
echo "Enter number of rows in the second matrix:"
|
styledEcho "Enter number of ", styleBright, "rows ", resetStyle, "in the second matrix:"
|
||||||
let r2: int = getInt()
|
let r2: int = getInt()
|
||||||
echo "Enter number of columns in the second matrix:"
|
styledEcho "Enter number of ", styleBright, "columns ", resetStyle, "in the second matrix:"
|
||||||
let c2: int = getInt()
|
let c2: int = getInt()
|
||||||
var m2 = newSeqWith(r2, newSeq[float](c2))
|
var m2 = newSeqWith(r2, newSeq[float](c2))
|
||||||
procedures.fillMatrix(m2, r2, c2)
|
procedures.fillMatrix(m2, r2, c2)
|
||||||
|
@ -93,7 +94,7 @@ proc dot* =
|
||||||
printMatrix(m)
|
printMatrix(m)
|
||||||
|
|
||||||
proc cross* =
|
proc cross* =
|
||||||
echo "VECTOR CROSS PRODUCT"
|
styledEcho styleBright, "Vector Cross Product"
|
||||||
|
|
||||||
type
|
type
|
||||||
VECTOR = array[3, float]
|
VECTOR = array[3, float]
|
||||||
|
@ -101,12 +102,12 @@ proc cross* =
|
||||||
v1: VECTOR
|
v1: VECTOR
|
||||||
v2: VECTOR
|
v2: VECTOR
|
||||||
|
|
||||||
echo "Enter numbers in the first vector:"
|
styledEcho "Enter numbers in the ", styleBright, "first ", resetStyle, "vector:"
|
||||||
for i in 0..2:
|
for i in 0..2:
|
||||||
echo "Enter item:"
|
echo "Enter item:"
|
||||||
v1[i] = getFloat()
|
v1[i] = getFloat()
|
||||||
|
|
||||||
echo "Enter numbers in the second vector:"
|
styledEcho "Enter numbers in the ", styleBright, "second ", resetStyle, "vector:"
|
||||||
for i in 0..2:
|
for i in 0..2:
|
||||||
echo "Enter item:"
|
echo "Enter item:"
|
||||||
v2[i] = getFloat()
|
v2[i] = getFloat()
|
||||||
|
|
Loading…
Reference in a new issue