修复6.0二维码的bug

This commit is contained in:
艾竹
2023-05-09 23:22:17 +08:00
parent e61b505dd3
commit f19d6c20ef
7 changed files with 497 additions and 18 deletions

View File

@@ -91,16 +91,16 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
}
private Models.ColorType _colorObject;
private Models.ColorType _colorType;
public Models.ColorType ColorType
{
get
{
return _colorObject;
return _colorType;
}
set
{
SetProperty(ref _colorObject, value);
SetProperty(ref _colorType, value);
}
}
@@ -715,21 +715,128 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
List<Color> result = new List<Color>();
for (var i = 0; i < count; i++)
{
//var colors = ColorGallery.GetGradient(ColorGallery.StandardThemeColors[i], 10);
//for (var j = 9; j >= 0; j--)
//{
// result.AddTo(colors[j]);
//}
var colors = GetGradient(ColorGallery.StandardThemeColors[i], 10);
for (var j = 9; j >= 0; j--)
{
result.Add(colors[j]);
}
}
{
//var colors = ColorGallery.GetGradient(Colors.Black, 10);
//for (var j = 9; j >= 0; j--)
//{
// result.AddTo(colors[j]);
//}
var colors = GetGradient(Colors.Black, 10);
for (var j = 9; j >= 0; j--)
{
result.Add(colors[j]);
}
}
return result.ToArray();
}
#endregion
#region Gradient Generation
/// <summary>
/// Returns brightness of the given color from 0..1
/// </summary>
/// <param name="color">Color</param>
/// <returns>Brightness of the given color from 0..1</returns>
private static double GetBrightness(Color color)
{
var summ = (double)color.R + color.G + color.B;
return summ / (255.0 * 3.0);
}
// Makes the given color lighter
private static Color Lighter(Color color, double power)
{
var totalAvailability = (255.0 * 3.0) - color.R + color.G + color.B;
double redAvailability;
double greenAvailability;
double blueAvailability;
double needToBeAdded;
if (color.R + color.G + color.B == 0)
{
redAvailability = 1.0 / 3.0;
greenAvailability = 1.0 / 3.0;
blueAvailability = 1.0 / 3.0;
needToBeAdded = power * 255.0 * 3.0;
}
else
{
redAvailability = (255.0 - color.R) / totalAvailability;
greenAvailability = (255.0 - color.G) / totalAvailability;
blueAvailability = (255.0 - color.B) / totalAvailability;
needToBeAdded = ((double)color.R + color.G + color.B) * (power - 1);
}
var result = Color.FromRgb(
(byte)(color.R + (byte)(redAvailability * needToBeAdded)),
(byte)(color.G + (byte)(greenAvailability * needToBeAdded)),
(byte)(color.B + (byte)(blueAvailability * needToBeAdded)));
return result;
}
// Makes the given color darker
private static Color Darker(Color color, double power)
{
var totalAvailability = (double)color.R + color.G + color.B;
var redAvailability = color.R / totalAvailability;
var greenAvailability = color.G / totalAvailability;
var blueAvailability = color.B / totalAvailability;
var needToBeAdded = (double)color.R + color.G + color.B;
needToBeAdded = needToBeAdded - (needToBeAdded * power);
var result = Color.FromRgb(
(byte)(color.R - (byte)(redAvailability * needToBeAdded)),
(byte)(color.G - (byte)(greenAvailability * needToBeAdded)),
(byte)(color.B - (byte)(blueAvailability * needToBeAdded)));
return result;
}
// Makes a new color from the given with new brightness
private static Color Rebright(Color color, double newBrightness)
{
var currentBrightness = GetBrightness(color);
var power = DoubleUtil.AreClose(currentBrightness, 0.0) == false
? newBrightness / currentBrightness
: 1.0 + newBrightness;
// TODO: round power to make nice numbers
// ...
if (power > 1.0)
{
return Lighter(color, power);
}
return Darker(color, power);
}
/// <summary>
/// Makes gradient colors from lighter to darker
/// </summary>
/// <param name="color">Base color</param>
/// <param name="count">Count of items in the gradient</param>
/// <returns>Colors from lighter to darker</returns>
public static Color[] GetGradient(Color color, int count)
{
const double lowBrightness = 0.15;
const double highBrightness = 0.85;
var result = new Color[count];
for (var i = 0; i < count; i++)
{
var brightness = lowBrightness + (i * (highBrightness - lowBrightness) / count);
result[count - i - 1] = Rebright(color, brightness);
}
return result;
}
#endregion
}
}