Added write-braille.ps1

This commit is contained in:
Markus Fleschutz 2020-12-22 08:24:30 +00:00
parent cc399370af
commit b719c3a575
3 changed files with 410 additions and 45 deletions

View File

@ -61,6 +61,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [wakeup.ps1](Scripts/wakeup.ps1) - sends a magic packet to the given computer, waking him up
* [write-big.ps1](Scripts/write-big.ps1) - writes the given text in big letters
* [write-blue.ps1](Scripts/write-blue.ps1) - writes the given text in a blue foreground color
* [write-braille.ps1](Scripts/write-braille.ps1) - writes the given text in Braille
* [write-green.ps1](Scripts/write-green.ps1) - writes the given text in a green foreground color
* [write-morse-code.ps1](Scripts/write-morse-code.ps1) - writes the given text in Morse code
* [write-MOTD.ps1](Scripts/write-MOTD.ps1) - writes the message of the day (MOTD)

360
Scripts/write-braille.ps1 Executable file
View File

@ -0,0 +1,360 @@
#!/snap/bin/powershell
# Syntax: ./write-braille.ps1 [<text>]
# Description: writes the given text in Braille
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
param([String]$Text)
function BrailleA() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "oo" }
3 { return "oo" }
}
}
function BrailleB() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".o" }
3 { return "oo" }
}
}
function BrailleC() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "oo" }
3 { return "oo" }
}
}
function BrailleD() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "o." }
3 { return "oo" }
}
}
function BrailleE() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "o." }
3 { return "oo" }
}
}
function BrailleF() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".o" }
3 { return "oo" }
}
}
function BrailleG() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".." }
3 { return "oo" }
}
}
function BrailleH() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".." }
3 { return "oo" }
}
}
function BrailleI() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".o" }
3 { return "oo" }
}
}
function BrailleJ() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".." }
3 { return "oo" }
}
}
function BrailleK() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "oo" }
3 { return ".o" }
}
}
function BrailleL() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".o" }
3 { return ".o" }
}
}
function BrailleM() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "oo" }
3 { return ".o" }
}
}
function BrailleN() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "o." }
3 { return ".o" }
}
}
function BrailleO() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "o." }
3 { return ".o" }
}
}
function BrailleP() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".o" }
3 { return ".o" }
}
}
function BrailleQ() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".." }
3 { return ".o" }
}
}
function BrailleR() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".." }
3 { return ".o" }
}
}
function BrailleS() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".o" }
3 { return ".o" }
}
}
function BrailleT() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".." }
3 { return ".o" }
}
}
function BrailleU() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "oo" }
3 { return ".." }
}
}
function BrailleV() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".o" }
3 { return ".." }
}
}
function BrailleW() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".." }
3 { return "o." }
}
}
function BrailleX() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "oo" }
3 { return ".." }
}
}
function BrailleY() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "o." }
3 { return ".." }
}
}
function BrailleZ() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "o." }
3 { return ".." }
}
}
function Braille1() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "oo" }
3 { return "oo" }
}
}
function Braille2() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".o" }
3 { return "oo" }
}
}
function Braille3() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "oo" }
3 { return "oo" }
}
}
function Braille4() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return "o." }
3 { return "oo" }
}
}
function Braille5() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return "o." }
3 { return "oo" }
}
}
function Braille6() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".o" }
3 { return "oo" }
}
}
function Braille7() { param([Int]$Row)
switch($Row) {
1 { return ".." }
2 { return ".." }
3 { return "oo" }
}
}
function Braille8() { param([Int]$Row)
switch($Row) {
1 { return ".o" }
2 { return ".." }
3 { return "oo" }
}
}
function Braille9() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".o" }
3 { return "oo" }
}
}
function Braille0() { param([Int]$Row)
switch($Row) {
1 { return "o." }
2 { return ".." }
3 { return "oo" }
}
}
function BrailleChar() { param([String]$Char, [Int]$Row)
switch($Char) {
'A' { return BrailleA $Row }
'B' { return BrailleB $Row }
'C' { return BrailleC $Row }
'D' { return BrailleD $Row }
'E' { return BrailleE $Row }
'F' { return BrailleF $Row }
'G' { return BrailleG $Row }
'H' { return BrailleH $Row }
'I' { return BrailleI $Row }
'J' { return BrailleJ $Row }
'K' { return BrailleK $Row }
'L' { return BrailleL $Row }
'M' { return BrailleM $Row }
'N' { return BrailleN $Row }
'O' { return BrailleO $Row }
'P' { return BrailleP $Row }
'Q' { return BrailleQ $Row }
'R' { return BrailleR $Row }
'S' { return BrailleS $Row }
'T' { return BrailleT $Row }
'U' { return BrailleU $Row }
'V' { return BrailleV $Row }
'W' { return BrailleW $Row }
'X' { return BrailleX $Row }
'Y' { return BrailleY $Row }
'Z' { return BrailleZ $Row }
'1' { return Braille1 $Row }
'2' { return Braille2 $Row }
'3' { return Braille3 $Row }
'4' { return Braille4 $Row }
'5' { return Braille5 $Row }
'6' { return Braille6 $Row }
'7' { return Braille7 $Row }
'8' { return Braille8 $Row }
'9' { return Braille9 $Row }
'0' { return Braille0 $Row }
}
return " "
}
try {
if ($Text -eq "" ) {
[String]$Text = read-host "Enter text to write"
}
[char[]]$ArrayOfChars = $Text.ToUpper()
write-output ""
for ($Row = 1; $Row -lt 4; $Row++) {
$Line = ""
foreach($Char in $ArrayOfChars) {
$Line += BrailleChar $Char $Row
$Line += " "
}
write-output $Line
}
write-output ""
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -7,61 +7,64 @@
# License: CC0
param([String]$Text)
$OneTimeUnit = 100 # milliseconds
function gap() { param([Int]$Length)
for ($i = 1; $i -lt $Length; $i++) {
write-host " " -nonewline
}
start-sleep -milliseconds ($Length * $OneTimeUnit)
}
function dot() {
write-host "." -nonewline
start-sleep -milliseconds 100
start-sleep -milliseconds $OneTimeUnit # signal
}
function dash() {
write-host "-" -nonewline
start-sleep -milliseconds 300
}
function pause() {
write-host " " -nonewline
start-sleep -milliseconds 400
write-host "_" -nonewline
start-sleep -milliseconds (3 * $OneTimeUnit) # signal
}
function Char2MorseCode() { param([String]$Char)
switch($Char) {
'A' { dot; dash }
'B' { dash; dot; dot; dot }
'C' { dash; dot; dash; dot }
'D' { dash; dot; dot }
'E' { dot }
'F' { dot; dot; dash; dot }
'G' { dash; dash; dot }
'H' { dot; dot; dot; dot }
'I' { dot; dot }
'J' { dot; dash; dash; dash }
'K' { dash; dot; dash }
'L' { dot; dash; dot; dot }
'M' { dash; dash }
'N' { dash; dot }
'O' { dash; dash; dash }
'P' { dot; dash; dash; dot }
'Q' { dash; dash; dot; dash }
'R' { dot; dash; dot }
'S' { dot; dot; dot }
'T' { dash }
'U' { dot; dot; dash }
'V' { dot; dot; dot; dash }
'W' { dot; dash; dash }
'X' { dash; dot; dot; dash }
'Y' { dash; dot; dash; dash }
'Z' { dash; dash; dot; dot }
'1' { dot; dash; dash; dash; dash }
'2' { dot; dot; dash; dash; dash }
'3' { dot; dot; dot; dash; dash }
'4' { dot; dot; dot; dot; dash }
'5' { dot; dot; dot; dot; dot }
'6' { dash; dot; dot; dot; dot }
'7' { dash; dash; dot; dot; dot }
'8' { dash; dash; dash; dot; dot }
'9' { dash; dash; dash; dash; dot }
'0' { dash; dash; dash; dash; dash }
default { pause }
'A' { dot; gap 1; dash; gap 3 }
'B' { dash; gap 1; dot; gap 1; dot; gap 1; dot; gap 3 }
'C' { dash; gap 1; dot; gap 1; dash; gap 1; dot; gap 3 }
'D' { dash; gap 1; dot; gap 1; dot; gap 3 }
'E' { dot; gap 3 }
'F' { dot; gap 1; dot; gap 1; dash; gap 1; dot; gap 3 }
'G' { dash; gap 1; dash; gap 1; dot; gap 3 }
'H' { dot; gap 1; dot; gap 1; dot; gap 1; dot; gap 3 }
'I' { dot; gap 1; dot; gap 3 }
'J' { dot; gap 1; dash; gap 1; dash; gap 1; dash; gap 3 }
'K' { dash; gap 1; dot; gap 1; dash; gap 3 }
'L' { dot; gap 1; dash; gap 1; dot; gap 1; dot; gap 3 }
'M' { dash; gap 1; dash; gap 3 }
'N' { dash; gap 1; dot; gap 3 }
'O' { dash; gap 1; dash; gap 1; dash; gap 3 }
'P' { dot; gap 1; dash; gap 1; dash; gap 1; dot; gap 3 }
'Q' { dash; gap 1; dash; gap 1; dot; gap 1; dash; gap 3 }
'R' { dot; gap 1; dash; gap 1; dot; gap 3 }
'S' { dot; gap 1; dot; gap 1; dot; gap 3 }
'T' { dash; gap 3 }
'U' { dot; gap 1; dot; gap 1; dash; gap 3 }
'V' { dot; gap 1; dot; gap 1; dot; gap 1; dash; gap 3 }
'W' { dot; gap 1; dash; gap 1; dash; gap 3 }
'X' { dash; gap 1; dot; gap 1; dot; gap 1; dash; gap 3 }
'Y' { dash; gap 1; dot; gap 1; dash; gap 1; dash; gap 3 }
'Z' { dash; gap 1; dash; gap 1; dot; gap 1; dot; gap 3 }
'1' { dot; gap 1; dash; gap 1; dash; gap 1; dash; gap 1; dash; gap 3 }
'2' { dot; gap 1; dot; gap 1; dash; gap 1; dash; gap 1; dash; gap 3 }
'3' { dot; gap 1; dot; gap 1; dot; gap 1; dash; gap 1; dash; gap 3 }
'4' { dot; gap 1; dot; gap 1; dot; gap 1; dot; gap 1; dash; gap 3 }
'5' { dot; gap 1; dot; gap 1; dot; gap 1; dot; gap 1; dot; gap 3 }
'6' { dash; gap 1; dot; gap 1; dot; gap 1; dot; gap 1; dot; gap 3 }
'7' { dash; gap 1; dash; gap 1; dot; gap 1; dot; gap 1; dot; gap 3 }
'8' { dash; gap 1; dash; gap 1; dash; gap 1; dot; gap 1; dot; gap 3 }
'9' { dash; gap 1; dash; gap 1; dash; gap 1; dash; gap 1; dot; gap 3 }
'0' { dash; gap 1; dash; gap 1; dash; gap 1; dash; gap 1; dash; gap 3 }
default { gap 7 } # medium gap (between words)
}
}
@ -74,6 +77,7 @@ try {
Char2MorseCode $Char
}
write-host ""
write-host ""
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"