mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 01:14:16 +01:00
130 lines
3.5 KiB
Markdown
130 lines
3.5 KiB
Markdown
|
The *write-xmas-tree.ps1* Script
|
||
|
===========================
|
||
|
|
||
|
This PowerShell script writes a christmas tree to the terminal.
|
||
|
|
||
|
Parameters
|
||
|
----------
|
||
|
```powershell
|
||
|
/home/markus/Repos/PowerShell/scripts/write-xmas-tree.ps1 [[-Size] <Array>] [[-XPos] <Int32>] [[-colors] <Array>] [[-Idx] <Int32>] [[-count] <Int32>] [[-duration] <Int32>] [<CommonParameters>]
|
||
|
|
||
|
-Size <Array>
|
||
|
|
||
|
Required? false
|
||
|
Position? 1
|
||
|
Default value @(21,8,4)
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
-XPos <Int32>
|
||
|
tree height, trunk width, trunk height
|
||
|
|
||
|
Required? false
|
||
|
Position? 2
|
||
|
Default value 50
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
-colors <Array>
|
||
|
starting x position
|
||
|
|
||
|
Required? false
|
||
|
Position? 3
|
||
|
Default value @("blue", "green", "cyan", "red", "yellow", "magenta")
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
-Idx <Int32>
|
||
|
|
||
|
Required? false
|
||
|
Position? 4
|
||
|
Default value (Get-Random -Min 0 -Max ($colors.Length-1))
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
-count <Int32>
|
||
|
|
||
|
Required? false
|
||
|
Position? 5
|
||
|
Default value 100
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
-duration <Int32>
|
||
|
|
||
|
Required? false
|
||
|
Position? 6
|
||
|
Default value 250
|
||
|
Accept pipeline input? false
|
||
|
Accept wildcard characters? false
|
||
|
|
||
|
[<CommonParameters>]
|
||
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
||
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
||
|
```
|
||
|
|
||
|
Example
|
||
|
-------
|
||
|
```powershell
|
||
|
PS> ./write-xmas-tree.ps1
|
||
|
|
||
|
```
|
||
|
|
||
|
Notes
|
||
|
-----
|
||
|
Author: Markus Fleschutz | License: CC0
|
||
|
|
||
|
Related Links
|
||
|
-------------
|
||
|
https://github.com/fleschutz/PowerShell
|
||
|
|
||
|
Script Content
|
||
|
--------------
|
||
|
```powershell
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Writes a Xmas tree
|
||
|
.DESCRIPTION
|
||
|
This PowerShell script writes a christmas tree to the terminal.
|
||
|
.EXAMPLE
|
||
|
PS> ./write-xmas-tree.ps1
|
||
|
.LINK
|
||
|
https://github.com/fleschutz/PowerShell
|
||
|
.NOTES
|
||
|
Author: Markus Fleschutz | License: CC0
|
||
|
#>
|
||
|
|
||
|
param( [array]$Size=@(21,8,4), # tree height, trunk width, trunk height
|
||
|
[int]$XPos=50, # starting x position
|
||
|
[array]$colors = @("blue", "green", "cyan", "red", "yellow", "magenta"),
|
||
|
[int]$Idx = (Get-Random -Min 0 -Max ($colors.Length-1)),
|
||
|
[int]$count = 100,
|
||
|
[int]$duration = 250) # ms
|
||
|
|
||
|
Clear-Host
|
||
|
do {
|
||
|
[console]::SetCursorPosition(0,0)
|
||
|
Write-Host "`n`t`t`tMerry Christmas" -foregroundColor yellow
|
||
|
Write-Host "`t`t`t &" -foregroundColor yellow
|
||
|
Write-Host "`t`t`t Happy New Year" -foregroundColor yellow
|
||
|
for ( $i=1; $i -le $Size[0]; $i++ ) {
|
||
|
$line = " " * ($XPos - $i) + "*" * ($i * 2)
|
||
|
$Idx = $Idx % $colors.Length
|
||
|
Write-Host $line -foregroundColor $colors[$Idx]
|
||
|
$Idx++
|
||
|
}
|
||
|
|
||
|
for ( $j=1; $j -le $Size[2]; $j++ ){
|
||
|
$line = " " * ( $XPos - ( $Size[1] / 2 ) ) + "#" * $Size[1]
|
||
|
Write-Host $line -foregroundColor DarkGreen
|
||
|
}
|
||
|
|
||
|
|
||
|
Start-Sleep -milliseconds $duration
|
||
|
$count--
|
||
|
} while ($count -gt 0)
|
||
|
|
||
|
```
|
||
|
|
||
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:52:02)*
|