external help file | Module Name | online version | schema |
---|---|---|---|
Pansies-help.xml |
Pansies |
2.0.0 |
Get the Hue complement color
Get-Complement [-Color] <RgbColor> [-HighContrast] [-BlackAndWhite] [-Passthru]
Returns a color that is 180 degrees opposite around the Hue component of the HSL color space.
The primary reason for Get-Complement to exist is for generating contrasting colors for foreground and background. For that reason, it's usually called with -HighContrast
mode, which changes the lightness or darkness to increase the contrast of the returned color.
It also has a -BlackAndWhite
switch that causes it to assume only 16 colors will work (PowerLine currently uses this mode by default because so many terminals don't support more --including Windows 10 prior to Creators Update). In BlackAndWhite mode, it always returns White or Black.
PS C:\> Get-Complement Cyan
Gets the color Red back, as the complement for Cyan.
PS C:\> $Background, $Foreground = Get-Complement Cyan -Passthru -BlackAndWhite
PS C:\> Microsoft.PowerShell.Utility\Write-Host " Hello World " -Foreground $Foreground.ConsoleColor -Background $Background.ConsoleColor
This example shows how using -Passthru
returns both the original color and the contrasting color, and how using -BlackAndWhite
results in a better contrast when you're being forced to use BlackAndWhite (as with the built-in Write-Host command).
You can try the example without -BlackAndWhite
to see the difference: with it, you'll get Black on Cyan, without, you'll get Red on Cyan. Note that using -HighContrast will make almost no difference if you're using the BlackAndWhite
property, because downsampling to 16 colors has to result in either Red or DarkRed...
The source color to calculate the complement of
Type: RgbColor
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Force the luminance to have "enough" contrast
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Returns either black or white to get a readable contrast color.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
If set, output the input $Color before the complement
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
The color to find a complement for
The complement of the input color