Skip to content

Commit

Permalink
Added the possibility to get split complementary color (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Oct 31, 2023
1 parent 766c613 commit ff5e454
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
26 changes: 26 additions & 0 deletions ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,32 @@ public static Color GetComplementaryColor(Color baseColor)
// Convert the complementary hue back to RGB
return HSLToColor(complementaryHue, s, l);
}

public static Color[] GenerateSplitComplementaryColors(Color baseColor)
{
Color[] splitComplementaryColors = new Color[3];

// Convert the base color to HSL
float h, s, l;
ColorToHSL(baseColor, out h, out s, out l);

// Calculate the angle to the complementary color
float complementaryAngle = (h + 0.5f) % 1.0f;

// Calculate the angles to the split complementary colors
float angle1 = (complementaryAngle + 1.0f / 6.0f) % 1.0f;
float angle2 = (complementaryAngle + 5.0f / 6.0f) % 1.0f;

// Generate the split-complementary colors
splitComplementaryColors[0] = HSLToColor(angle1, s, l);
splitComplementaryColors[1] = HSLToColor(angle2, s, l);

// Include the base color as well
splitComplementaryColors[2] = baseColor;

return splitComplementaryColors;
}

public static void ColorToHSL(Color color, out float h, out float s, out float l)
{
float r = (float)color.R / 255f;
Expand Down
35 changes: 35 additions & 0 deletions ColorPicker/Pages/HarmoniesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,41 @@
CornerRadius="10"
Cursor="Hand"
MouseLeftButtonUp="ComplementaryBorder_MouseLeftButtonUp" />
<TextBlock
Margin="5"
FontWeight="Bold"
Text="{x:Static lang:Resources.SplitComplementary}" />
<StackPanel Orientation="Horizontal">
<Border
x:Name="SplitBorder1"
Width="50"
Height="50"
Margin="10 0 0 0"
HorizontalAlignment="Left"
d:Background="White"
CornerRadius="10 0 0 10"
Cursor="Hand"
MouseLeftButtonUp="ComplementaryBorder_MouseLeftButtonUp" />
<Border
x:Name="SplitBorder2"
Width="50"
Height="50"
Margin="0 10"
HorizontalAlignment="Left"
d:Background="White"
Cursor="Hand"
MouseLeftButtonUp="ComplementaryBorder_MouseLeftButtonUp" />
<Border
x:Name="SplitBorder3"
Width="50"
Height="50"
Margin="0 10"
HorizontalAlignment="Left"
d:Background="White"
CornerRadius="0 10 10 0"
Cursor="Hand"
MouseLeftButtonUp="ComplementaryBorder_MouseLeftButtonUp" />
</StackPanel>
</StackPanel>
</Grid>
</Page>
23 changes: 16 additions & 7 deletions ColorPicker/Pages/HarmoniesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MIT License
using ColorPicker.Classes;
using ColorPicker.Enums;
using ColorPicker.Windows;
using Synethia;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -49,11 +50,13 @@ namespace ColorPicker.Pages
/// </summary>
public partial class HarmoniesPage : Page
{
public HarmoniesPage()
bool code = Global.Settings.UseSynethia ? false : true; // checks if the code as already been implemented
public HarmoniesPage()
{
InitializeComponent();
InitUI();
}
Loaded += (o, e) => SynethiaManager.InjectSynethiaCode(this, Global.SynethiaConfig.PagesInfo, 7, ref code); // injects the code in the page
}

private void InitUI()
{
Expand Down Expand Up @@ -91,7 +94,16 @@ internal void InitHarmonies()
// Complementary
var complementary = Global.GetComplementaryColor(color);
ComplementaryBorder.Background = new SolidColorBrush { Color = complementary };
ComplementaryBorder.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Color = complementary };
ComplementaryBorder.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Opacity = 0.2, Color = complementary };

// Split complementary
var splitComplementaries = Global.GenerateSplitComplementaryColors(color);
SplitBorder1.Background = new SolidColorBrush { Color = splitComplementaries[0] };
SplitBorder1.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Opacity = 0.2, Color = splitComplementaries[0] };
SplitBorder2.Background = new SolidColorBrush { Color = splitComplementaries[1] };
SplitBorder2.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Opacity = 0.2, Color = splitComplementaries[1] };
SplitBorder3.Background = new SolidColorBrush { Color = splitComplementaries[2] };
SplitBorder3.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Opacity = 0.2, Color = splitComplementaries[2] };
}

internal ColorInfo ColorInfo { get; set; }
Expand Down Expand Up @@ -349,10 +361,7 @@ internal void ColorBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs

private void ComplementaryBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
new ColorDetailsWindow(new()
{
Color = Color.FromRgb(ColorInfo.RGB.R, ColorInfo.RGB.G, ColorInfo.RGB.B)
}).Show();
new ColorDetailsWindow((SolidColorBrush)((Border)sender).Background).Show();
}
}
}

0 comments on commit ff5e454

Please sign in to comment.