Last active
February 4, 2021 21:04
-
-
Save SeidChr/6dcae356760197d3d9147a3414829945 to your computer and use it in GitHub Desktop.
Powershell Console Gradient Foreground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1..100 | % { Gradient -Start "0000FF" -End "FF0000" -Grade ($_ * (1/100)) -Text "Moin" }