Created
September 22, 2016 21:29
-
-
Save lzybkr/05bf1fe79852ee5f6facaf62999e53a7 to your computer and use it in GitHub Desktop.
This file contains 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
[CmdletBinding(DefaultParameterSetName = 'FixedG')] | |
param( | |
[Parameter(ParameterSetName = 'FixedR', Mandatory)] | |
[ValidateRange(0, 255)] | |
$fixedR, | |
[Parameter(ParameterSetName = 'FixedG')] | |
[ValidateRange(0, 255)] | |
[int]$fixedG = 105, | |
[Parameter(ParameterSetName = 'FixedB', Mandatory)] | |
[ValidateRange(0, 255)] | |
[int]$fixedB, | |
[char]$Character = [char]" ") | |
$h = [Console]::WindowHeight - 4 # Use most of the vertical | |
$w = [Console]::BufferWidth - 2 # and even more of the horizontal | |
$e = [string][char]0x1b | |
$sb = [System.Text.StringBuilder]::new() | |
$null = $sb.AppendLine("$e[mPrinting 24bit gradient with ANSI sequences using powershell") | |
# Run cycles. Use {ESC [ 48 ; 2 ; R ; G ; B m} to set background | |
# RGB color of the next printing character (space in this example) | |
for ($l = 0; $l -lt $h; $l++) | |
{ | |
$c1 = [int]($l*255/$h) | |
$null = $sb.Append("$e[m ") | |
for ($c = 0; $c -lt $w; $c++) | |
{ | |
$c2 = [int]($c*255/$w) | |
switch ($PSCmdlet.ParameterSetName) | |
{ | |
'FixedR' { $null = $sb.Append("$e[48;2;$fixedR;$c1;${c2}m$Character"); break; } | |
'FixedG' { $null = $sb.Append("$e[48;2;$c1;$fixedG;${c2}m$Character"); break; } | |
'FixedB' { $null = $sb.Append("$e[48;2;$c2;$c1;${fixedB}m$Character"); break; } | |
} | |
} | |
$null = $sb.Append("$e[m ") | |
} | |
$null = $sb.Append( "Gradient done") | |
$sb.ToString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment