PowerShell/docs/write-matrix.md

85 lines
2.1 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *write-matrix.ps1*
========================
2022-11-17 20:02:26 +01:00
write-matrix.ps1
2022-11-17 19:46:02 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2022-11-17 19:46:02 +01:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Writes the matrix
.DESCRIPTION
This PowerShell script writes the animated Matrix.
.EXAMPLE
2023-09-01 17:53:03 +02:00
PS> ./write-matrix.ps1
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2023-09-01 17:53:03 +02:00
function CalculateMatrix { param([int]$pos, [char]$letter)
[int]$width = $rui.MaxWindowSize.Width
[int]$height = $rui.MaxWindowSize.Height
2022-11-17 20:02:26 +01:00
[int]$y = 0
2023-09-01 17:53:03 +02:00
for ([int]$x = 0; $x -lt $width; $x++) {
if ($x -eq $pos) {
$global:buf[$y * $width + $x] = $letter
2022-11-17 20:02:26 +01:00
} else {
2023-09-01 17:53:03 +02:00
$global:buf[$y * $width + $x] = [char]32
2022-11-17 20:02:26 +01:00
}
}
2023-09-01 17:53:03 +02:00
for ([int]$y = ($height - 1); $y -gt 0; $y--) {
for ([int]$x = 0; $x -lt $width; $x++) {
$global:buf[$y * $width + $x] = $global:buf[($y - 1) * $width + $x]
2022-11-17 20:02:26 +01:00
}
}
}
function NextLetter {
if ($global:index -eq 6) { $global:index = 0; $global:pos = [int]$global:generator.next(0, $rui.MaxWindowSize.Width) }
switch($global:index++) {
0 { return 'X' }
1 { return 'I' }
2 { return 'R' }
3 { return 'T' }
4 { return 'A' }
5 { return 'M' }
}
}
$ui = (Get-Host).ui
$rui = $ui.rawui
$buffer0 = ""
2023-09-01 17:53:03 +02:00
1..($rui.MaxWindowSize.Width * $rui.MaxWindowSize.Height) | foreach { $buffer0 += " " }
2022-11-17 20:02:26 +01:00
$global:buf = $buffer0.ToCharArray()
$global:generator = New-Object System.Random
$global:pos = [int]$global:generator.next(0, $rui.MaxWindowSize.Width)
$global:index = 0
while ($true) {
2023-09-01 17:53:03 +02:00
$letter = NextLetter
CalculateMatrix $global:pos $letter
2022-11-17 20:02:26 +01:00
[console]::SetCursorPosition(0,0)
2023-09-01 17:53:03 +02:00
[string]$screen = New-Object system.string($global:buf, 0, $global:buf.Length)
Write-Host -foreground green $screen -noNewline
Start-Sleep -milliseconds 30
2022-11-17 20:02:26 +01:00
}
exit 0 # success
2023-10-19 08:12:00 +02:00
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2024-05-19 10:25:56 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of write-matrix.ps1 as of 05/19/2024 10:25:27)*