Skip to content

Instantly share code, notes, and snippets.

@SeidChr
Last active February 4, 2021 21:04
Show Gist options
  • Save SeidChr/6dcae356760197d3d9147a3414829945 to your computer and use it in GitHub Desktop.
Save SeidChr/6dcae356760197d3d9147a3414829945 to your computer and use it in GitHub Desktop.
Powershell Console Gradient Foreground
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
function Gradient {
param(
[string] $Start,
[string] $End,
[double] $Grade,
[string] $Text
)
$marker = [char]27
$code = 0..2 | ForEach-Object {
$offset = 0 + $_ * 2
$a = [int]("0x" + $Start.Substring($offset, 2))
$b = [int]("0x" + $End.Substring($offset, 2))
[string][int]((($b - $a) * $Grade) + $a)
} | Join-String -Separator ";"
"$marker[38;2;$($code)m$Text$marker[0m"
}
@SeidChr
Copy link
Author

SeidChr commented Feb 4, 2021

1..100 | % { Gradient -Start "0000FF" -End "FF0000" -Grade ($_ * (1/100)) -Text "Moin" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment