Skip to content

Commit 6bdf29b

Browse files
committed
feat: Added methods to increase/decrease components on colors.
1 parent 47abbb7 commit 6bdf29b

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

ColorSetKit/ColorExtensions.cs

+30
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public static System.Windows.Media.Color ByChangingHue( this System.Windows.Medi
122122
return FromHSL( h, hsl.Saturation, hsl.Lightness, rgb.Alpha );
123123
}
124124

125+
public static System.Windows.Media.Color ByIncreasingHue( this System.Windows.Media.Color self, double h )
126+
{
127+
return self.ByChangingHue( self.GetHSL().Hue + h );
128+
}
129+
130+
public static System.Windows.Media.Color ByDecreasingHue( this System.Windows.Media.Color self, double h )
131+
{
132+
return self.ByChangingHue( self.GetHSL().Hue - h );
133+
}
134+
125135
public static System.Windows.Media.Color ByChangingSaturation( this System.Windows.Media.Color self, double s )
126136
{
127137
RGBComponents rgb = self.GetRGB();
@@ -130,6 +140,16 @@ public static System.Windows.Media.Color ByChangingSaturation( this System.Windo
130140
return FromHSL( hsl.Hue, s, hsl.Lightness, rgb.Alpha );
131141
}
132142

143+
public static System.Windows.Media.Color ByIncreasingSaturation( this System.Windows.Media.Color self, double s )
144+
{
145+
return self.ByChangingSaturation( self.GetHSL().Saturation + s );
146+
}
147+
148+
public static System.Windows.Media.Color ByDecreasingSaturation( this System.Windows.Media.Color self, double s )
149+
{
150+
return self.ByChangingSaturation( self.GetHSL().Saturation - s );
151+
}
152+
133153
public static System.Windows.Media.Color ByChangingLightness( this System.Windows.Media.Color self, double l )
134154
{
135155
RGBComponents rgb = self.GetRGB();
@@ -138,6 +158,16 @@ public static System.Windows.Media.Color ByChangingLightness( this System.Window
138158
return FromHSL( hsl.Hue, hsl.Saturation, l, rgb.Alpha );
139159
}
140160

161+
public static System.Windows.Media.Color ByIncreasingLightness( this System.Windows.Media.Color self, double l )
162+
{
163+
return self.ByChangingLightness( self.GetHSL().Lightness + l );
164+
}
165+
166+
public static System.Windows.Media.Color ByDecreasingLightness( this System.Windows.Media.Color self, double l )
167+
{
168+
return self.ByChangingLightness( self.GetHSL().Lightness - l );
169+
}
170+
141171
private static RGB HSLToRGB( double h, double s, double l )
142172
{
143173
double t1;

ColorSetKit/ColorSetKit.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Nullable>enable</Nullable>
1212
<WarningsAsErrors>nullable;CS8600;CS8602;CS8603;CS8625</WarningsAsErrors>
1313
<RepositoryUrl>https://github.com/DigiDNA/ColorSet</RepositoryUrl>
14-
<Version>2.0.2</Version>
14+
<Version>2.0.3</Version>
1515
</PropertyGroup>
1616

1717
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ColorSetKit/SolidColorBrushExtensions.cs

+41-3
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,61 @@ public static System.Windows.Media.SolidColorBrush ByChangingHue( this System.Wi
3535
{
3636
return new System.Windows.Media.SolidColorBrush( self.Color.ByChangingHue( h ) );
3737
}
38+
public static System.Windows.Media.SolidColorBrush ByIncreasingHue( this System.Windows.Media.SolidColorBrush self, double h )
39+
{
40+
return new System.Windows.Media.SolidColorBrush( self.Color.ByIncreasingHue( h ) );
41+
}
42+
public static System.Windows.Media.SolidColorBrush ByDecreasingHue( this System.Windows.Media.SolidColorBrush self, double h )
43+
{
44+
return new System.Windows.Media.SolidColorBrush( self.Color.ByDecreasingHue( h ) );
45+
}
3846

3947
public static System.Windows.Media.SolidColorBrush ByChangingSaturation( this System.Windows.Media.SolidColorBrush self, double s )
4048
{
41-
return new System.Windows.Media.SolidColorBrush( self.Color.ByChangingHue( s ) );
49+
return new System.Windows.Media.SolidColorBrush( self.Color.ByChangingSaturation( s ) );
50+
}
51+
52+
public static System.Windows.Media.SolidColorBrush ByIncreasingSaturation( this System.Windows.Media.SolidColorBrush self, double s )
53+
{
54+
return new System.Windows.Media.SolidColorBrush( self.Color.ByIncreasingSaturation( s ) );
55+
}
56+
57+
public static System.Windows.Media.SolidColorBrush ByDecreasingSaturation( this System.Windows.Media.SolidColorBrush self, double s )
58+
{
59+
return new System.Windows.Media.SolidColorBrush( self.Color.ByDecreasingSaturation( s ) );
4260
}
4361

4462
public static System.Windows.Media.SolidColorBrush ByChangingLightness( this System.Windows.Media.SolidColorBrush self, double l )
4563
{
4664
return new System.Windows.Media.SolidColorBrush( self.Color.ByChangingLightness( l ) );
4765
}
4866

49-
public static System.Windows.Media.SolidColorBrush ByChangingOpacity( this System.Windows.Media.SolidColorBrush self, double l )
67+
public static System.Windows.Media.SolidColorBrush ByIncreasingLightness( this System.Windows.Media.SolidColorBrush self, double l )
68+
{
69+
return new System.Windows.Media.SolidColorBrush( self.Color.ByIncreasingLightness( l ) );
70+
}
71+
72+
public static System.Windows.Media.SolidColorBrush ByDecreasingLightness( this System.Windows.Media.SolidColorBrush self, double l )
73+
{
74+
return new System.Windows.Media.SolidColorBrush( self.Color.ByDecreasingLightness( l ) );
75+
}
76+
77+
public static System.Windows.Media.SolidColorBrush ByChangingOpacity( this System.Windows.Media.SolidColorBrush self, double o )
5078
{
5179
System.Windows.Media.SolidColorBrush copy = self.Clone();
52-
copy.Opacity = l;
80+
copy.Opacity = o;
5381

5482
return copy;
5583
}
84+
85+
public static System.Windows.Media.SolidColorBrush ByIncreasingOpacity( this System.Windows.Media.SolidColorBrush self, double o )
86+
{
87+
return self.ByChangingOpacity( self.Opacity + o );
88+
}
89+
90+
public static System.Windows.Media.SolidColorBrush ByDecreasingOpacity( this System.Windows.Media.SolidColorBrush self, double o )
91+
{
92+
return self.ByChangingOpacity( self.Opacity - o );
93+
}
5694
}
5795
}

0 commit comments

Comments
 (0)