mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 09:23:12 +01:00
Update write-matrix.ps1
This commit is contained in:
parent
41be046841
commit
9e52bbe4a8
@ -4,27 +4,27 @@
|
|||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script writes the animated Matrix.
|
This PowerShell script writes the animated Matrix.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./write-fractal
|
PS> ./write-matrix.ps1
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function CalculateMatrix { param([int]$Pos, [char]$Letter)
|
function CalculateMatrix { param([int]$pos, [char]$letter)
|
||||||
[int]$maxx = $rui.MaxWindowSize.Width
|
[int]$width = $rui.MaxWindowSize.Width
|
||||||
[int]$maxy = $rui.MaxWindowSize.Height
|
[int]$height = $rui.MaxWindowSize.Height
|
||||||
[int]$y = 0
|
[int]$y = 0
|
||||||
for ([int]$x = 0; $x -lt $maxx; $x++) {
|
for ([int]$x = 0; $x -lt $width; $x++) {
|
||||||
if ($x -eq $Pos) {
|
if ($x -eq $pos) {
|
||||||
$global:buf[$y * $maxx + $x] = $Letter
|
$global:buf[$y * $width + $x] = $letter
|
||||||
} else {
|
} else {
|
||||||
$global:buf[$y * $maxx + $x] = [char]32
|
$global:buf[$y * $width + $x] = [char]32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ([int]$y = ($maxy - 1); $y -gt 0; $y--) {
|
for ([int]$y = ($height - 1); $y -gt 0; $y--) {
|
||||||
for ([int]$x = 0; $x -lt $maxx; $x++) {
|
for ([int]$x = 0; $x -lt $width; $x++) {
|
||||||
$global:buf[$y * $maxx + $x] = $global:buf[($y - 1) * $maxx + $x]
|
$global:buf[$y * $width + $x] = $global:buf[($y - 1) * $width + $x]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,17 +44,18 @@ function NextLetter {
|
|||||||
$ui = (Get-Host).ui
|
$ui = (Get-Host).ui
|
||||||
$rui = $ui.rawui
|
$rui = $ui.rawui
|
||||||
$buffer0 = ""
|
$buffer0 = ""
|
||||||
1..($rui.MaxWindowSize.Width * $rui.MaxWindowSize.Height) | ForEach-Object { $buffer0 += " " }
|
1..($rui.MaxWindowSize.Width * $rui.MaxWindowSize.Height) | foreach { $buffer0 += " " }
|
||||||
$global:buf = $buffer0.ToCharArray()
|
$global:buf = $buffer0.ToCharArray()
|
||||||
$global:generator = New-Object System.Random
|
$global:generator = New-Object System.Random
|
||||||
$global:pos = [int]$global:generator.next(0, $rui.MaxWindowSize.Width)
|
$global:pos = [int]$global:generator.next(0, $rui.MaxWindowSize.Width)
|
||||||
$global:index = 0
|
$global:index = 0
|
||||||
|
|
||||||
while ($true) {
|
while ($true) {
|
||||||
$Letter = NextLetter
|
$letter = NextLetter
|
||||||
CalculateMatrix $global:pos $Letter
|
CalculateMatrix $global:pos $letter
|
||||||
[console]::SetCursorPosition(0,0)
|
[console]::SetCursorPosition(0,0)
|
||||||
[string]$Screen = New-Object system.string($global:buf, 0, $global:buf.Length)
|
[string]$screen = New-Object system.string($global:buf, 0, $global:buf.Length)
|
||||||
Write-Host -foreground green $Screen -noNewline
|
Write-Host -foreground green $screen -noNewline
|
||||||
|
Start-Sleep -milliseconds 30
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
Loading…
Reference in New Issue
Block a user