PowerShell/scripts/write-xmas-tree.ps1

38 lines
1.1 KiB
PowerShell
Raw Normal View History

2024-11-18 08:05:06 +01:00
# Writes a christmas tree to terminal
2024-11-18 07:42:17 +01:00
# Variable $Size = (tree_height, trunk_width, trunk_height)
# Variable $XPos = The starting x position on the terminal line
2024-11-18 08:05:06 +01:00
# Variables $colors = List of colors to use
2024-11-18 07:42:17 +01:00
# Random color pattern each execution
param (
2024-11-18 08:05:06 +01:00
[array]$Size=@(20,8,4),
2024-11-18 07:42:17 +01:00
[int]$XPos=50,
2024-11-18 08:05:06 +01:00
[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
2024-11-18 07:42:17 +01:00
)
2024-11-18 08:05:06 +01:00
Clear-Host
do {
[console]::SetCursorPosition(0,0)
Write-Host "`n`tMerry Christmas and a Happy New Year!`n`n" -foregroundColor Yellow
2024-11-18 07:42:17 +01:00
for ( $i=1; $i -le $Size[0]; $i++ ) {
2024-11-18 08:05:06 +01:00
$line = " " * ($XPos - $i) + "*" * ($i * 2)
$Idx = $Idx % $colors.Length
Write-Host $line -foregroundColor $colors[$Idx]
2024-11-18 07:42:17 +01:00
$Idx++
}
for ( $j=1; $j -le $Size[2]; $j++ ){
2024-11-18 08:05:06 +01:00
$line = " " * ( $XPos - ( $Size[1] / 2 ) ) + "#" * $Size[1]
Write-Host $line -foregroundColor DarkGreen
2024-11-18 07:42:17 +01:00
}
2024-11-18 08:05:06 +01:00
Start-Sleep -milliseconds $duration
2024-11-18 07:42:17 +01:00
2024-11-18 08:05:06 +01:00
$count--
} while ($count -gt 0)
2024-11-18 07:42:17 +01:00