-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
Pwsh/Parameters/Cleaner ParameterSets for ConvertTo-Hsv.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
function ConvertTo-HSV { | ||
<# | ||
.synopsis | ||
example to demonstrate another way to pipe array values | ||
.NOTES | ||
from JustinGrote in discord: <https://discord.com/channels/180528040881815552/447476117629304853/1178486715581734993> | ||
.EXAMPLE | ||
Pwsh> $c = | ||
[Pscustomobject]@{ | ||
Red = 100 | ||
Green = 200 | ||
Blue = 128 | ||
Alpha = 9 | ||
} | ||
Pwsh> $c | ||
Red Green Blue Alpha | ||
--- ----- ---- ----- | ||
100 200 128 9 | ||
Pwsh> $c | ConvertTo-HSV | ||
Hue Saturation Value | ||
--- ---------- ----- | ||
136.80 0.48 0.59 | ||
#> | ||
[CmdletBinding(DefaultParameterSetName='ByValue')] | ||
param ( | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='ByValue')] | ||
[ValidateRange(0, 255)] | ||
[int]$Red, | ||
|
||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ByValue')] | ||
[ValidateRange(0, 255)] | ||
[int]$Green, | ||
|
||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ByValue')] | ||
[ValidateRange(0, 255)] | ||
[int]$Blue, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'ByValue')] | ||
[ValidateRange(0, 255)] | ||
[int]$Alpha = 0, | ||
|
||
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName='ByColor')] | ||
[System.Drawing.Color]$Color | ||
) | ||
|
||
process { | ||
|
||
if ($PSCmdlet.ParameterSetName -eq 'ByValue') { | ||
$Color = [Drawing.Color]::FromArgb($Alpha, $Red, $Green, $Blue) | ||
} | ||
|
||
[PSCustomObject]@{ | ||
Hue = $Color.GetHue() | ||
Saturation = $Color.GetSaturation() | ||
Value = $Color.GetBrightness() | ||
PSTypeName = 'HSV' | ||
} | ||
} | ||
} | ||
$c = [Pscustomobject]@{ | ||
Red = 100 | ||
Green = 200 | ||
Blue = 128 | ||
Alpha = 9 | ||
} | ||
|
||
|
||
$c | ft -auto | ||
$c | ConvertTo-HSV | ft -auto |