Skip to content

Commit

Permalink
Merge pull request #862 from WildernessLabs/jorge-color-update
Browse files Browse the repository at this point in the history
Replace Color references from Meadow.Foundation.Core to Meadow.Contracts
  • Loading branch information
adrianstevens authored Dec 12, 2023
2 parents 4c081b4 + 7e8cd5e commit b24b5b5
Show file tree
Hide file tree
Showing 32 changed files with 129 additions and 991 deletions.
605 changes: 0 additions & 605 deletions Source/Meadow.Foundation.Core/Color.cs

This file was deleted.

48 changes: 0 additions & 48 deletions Source/Meadow.Foundation.Core/Extensions/ColorExtensions.cs

This file was deleted.

205 changes: 0 additions & 205 deletions Source/Meadow.Foundation.Core/Helpers/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,210 +34,5 @@ public static byte ByteToBCD(byte v)
result += (v % 10);
return (byte)(result & 0xff);
}

/// <summary>
/// HSL to RGB
/// </summary>
/// <param name="hue">Hue in degrees (0-359°)</param>
/// <param name="saturation">Saturation</param>
/// <param name="lightness">Brightness value</param>
/// <param name="r">The red component (0-1)</param>
/// <param name="g">The green component (0-1)</param>
/// <param name="b">The blue component (0-1)</param>
public static void HslToRgb(double hue, double saturation, double lightness, out double r, out double g, out double b)
{
double h = hue;
double R, G, B;

// hue parameter checking/fixing
if (h < 0)
{
h = 0;
}
else if (h > 360)
{
h %= 360;
}

//default to gray
R = G = B = lightness;

var v = (lightness <= 0.5) ?
(lightness * (1.0 + saturation)) :
(lightness + saturation - lightness * saturation);

if (v > 0)
{
double m;
double l = lightness;
double sv;
int sextant;
double fract, vsf, mid1, mid2;

m = l + l - v;
sv = (v - m) / v;
h /= 60.0;
sextant = (int)h;
fract = h - sextant;
vsf = v * sv * fract;
mid1 = m + vsf;
mid2 = v - vsf;
switch (sextant)
{
case 0:
R = v;
G = mid1;
B = m;
break;
case 1:
R = mid2;
G = v;
B = m;
break;
case 2:
R = m;
G = v;
B = mid1;
break;
case 3:
R = m;
G = mid2;
B = v;
break;
case 4:
R = mid1;
G = m;
B = v;
break;
case 5:
R = v;
G = m;
B = mid2;
break;
}
}

r = Clamp(R);
g = Clamp(G);
b = Clamp(B);
}

/// <summary>
/// HSV to RGB
/// </summary>
/// <param name="hue">Hue in degrees (0-359°)</param>
/// <param name="saturation">Saturation</param>
/// <param name="brightValue">Brightness value</param>
/// <param name="r">The red component (0-1)</param>
/// <param name="g">The green component (0-1)</param>
/// <param name="b">The blue component (0-1)</param>
public static void HsvToRgb(double hue, double saturation, double brightValue, out double r, out double g, out double b)
{
double H = hue;
double R, G, B;

// hue parameter checking/fixing
if (H < 0)
{
H = 0;
}
else if (H > 360)
{
H %= 360;
}

// if Brightness is turned off, then everything is zero.
if (brightValue <= 0)
{
R = G = B = 0;
}

// if saturation is turned off, then there is no color/hue. it's grayscale.
else if (saturation <= 0)
{
R = G = B = brightValue;
}
else // if we got here, then there is a color to create.
{
double hf = H / 60.0;
int i = (int)Math.Floor(hf);
double f = hf - i;
double pv = brightValue * (1 - saturation);
double qv = brightValue * (1 - saturation * f);
double tv = brightValue * (1 - saturation * (1 - f));

switch (i)
{

// Red Dominant
case 0:
R = brightValue;
G = tv;
B = pv;
break;

// Green Dominant
case 1:
R = qv;
G = brightValue;
B = pv;
break;
case 2:
R = pv;
G = brightValue;
B = tv;
break;

// Blue Dominant
case 3:
R = pv;
G = qv;
B = brightValue;
break;
case 4:
R = tv;
G = pv;
B = brightValue;
break;

// Red Red Dominant
case 5:
R = brightValue;
G = pv;
B = qv;
break;

// In case the math is out of bounds, this is a fix.
case 6:
R = brightValue;
G = tv;
B = pv;
break;
case -1:
R = brightValue;
G = pv;
B = qv;
break;

// If the color is not defined, go grayscale
default:
R = G = B = brightValue;
break;
}
}
r = Clamp(R);
g = Clamp(G);
b = Clamp(B);
}

/// <summary>
/// Clamp a value to 0 to 1
/// </summary>
static double Clamp(double i)
{
if (i < 0) return 0;
if (i > 1) return 1;
return i;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Include=".\Readme.md" Pack="true" PackagePath=""/>
<None Include=".\Readme.md" Pack="true" PackagePath="" />
<None Include="..\..\Source\icon.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void Clear(bool updateDisplay = false)
/// </summary>
/// <param name="fillColor"></param>
/// <param name="updateDisplay"></param>
public void Fill(Foundation.Color fillColor, bool updateDisplay = false)
public void Fill(Color fillColor, bool updateDisplay = false)
{
ShowComplete.WaitOne();
_pixelBuffer.Fill(fillColor);
Expand All @@ -225,7 +225,7 @@ public void Fill(Foundation.Color fillColor, bool updateDisplay = false)
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="fillColor"></param>
public void Fill(int x, int y, int width, int height, Foundation.Color fillColor)
public void Fill(int x, int y, int width, int height, Color fillColor)
{
ShowComplete.WaitOne();
_pixelBuffer.Fill(x, y, width, height, fillColor);
Expand All @@ -237,7 +237,7 @@ public void Fill(int x, int y, int width, int height, Foundation.Color fillColor
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="color"></param>
public void DrawPixel(int x, int y, Foundation.Color color)
public void DrawPixel(int x, int y, Color color)
{
ShowComplete.WaitOne();
_pixelBuffer.SetPixel(x, y, color);
Expand All @@ -252,7 +252,7 @@ public void DrawPixel(int x, int y, Foundation.Color color)
public void DrawPixel(int x, int y, bool colored)
{
ShowComplete.WaitOne();
DrawPixel(x, y, colored ? Foundation.Color.White : Foundation.Color.Black);
DrawPixel(x, y, colored ? Color.White : Color.Black);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override Task Run()
{
graphics.Clear();
graphics.CurrentFont = new Font8x12();
graphics.DrawText(0, 0, "Meadow F7", Meadow.Foundation.Color.White);
graphics.DrawText(0, 0, "Meadow F7", Color.White);
graphics.DrawRectangle(5, 14, 30, 10, true);

graphics.Show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override Task Run()
{
graphics.Clear();
graphics.CurrentFont = new Font8x12();
graphics.DrawText(0, 0, "Meadow F7", Meadow.Foundation.Color.White);
graphics.DrawText(0, 0, "Meadow F7", Color.White);
graphics.DrawRectangle(5, 14, 30, 10, true);

Resolver.Log.Info("Show...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using System;
Expand Down Expand Up @@ -110,37 +109,37 @@ void ColorFontTest()

graphics.Clear();

graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false);
graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Color.Red, false);

graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false);
graphics.DrawRectangle(140, 30, 40, 90, Color.Yellow, false);

graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false);
graphics.DrawCircle(160, 80, 40, Color.Cyan, false);

int indent = 5;
int spacing = 14;
int y = indent;

graphics.DrawText(indent, y, "Meadow + SSD1327!!");

graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red);
graphics.DrawText(indent, y += spacing, "Red", Color.Red);

graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple);
graphics.DrawText(indent, y += spacing, "Purple", Color.Purple);

graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet);
graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet);

graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue);
graphics.DrawText(indent, y += spacing, "Blue", Color.Blue);

graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan);
graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan);

graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen);
graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen);

graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow);
graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow);

graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow);
graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow);

graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange);
graphics.DrawText(indent, y += spacing, "Orange", Color.Orange);

graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown);
graphics.DrawText(indent, y += spacing, "Brown", Color.Brown);

graphics.Show();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public override Task Initialize()
public override Task Run()
{
graphics.Clear();
graphics.DrawCircle(120, 120, 100, Meadow.Foundation.Color.Cyan, false);
graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Meadow.Foundation.Color.BlueViolet, false);
graphics.DrawCircle(120, 120, 100, Color.Cyan, false);
graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Color.BlueViolet, false);
graphics.DrawText(120, 120, "Meadow F7", alignmentH: HorizontalAlignment.Center, alignmentV: VerticalAlignment.Center);
graphics.Show();

Expand Down
Loading

0 comments on commit b24b5b5

Please sign in to comment.