math-suite/Source/GraphingCalculator/Expression/VisualExpression.cs

65 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
namespace GraphingCalculator
{
public class VisualExpression : Expression
{
private static int rand_seed = 0x250D;
#region Variables
private Color color = Colors.Blue;
public Color Color { get { return color; } set { color = value; } }
private double thickness = 2;
public double Thickness { get { return thickness; } set { thickness = value; } }
public bool IsVisible { get; set; }
#endregion
#region Constructors
public VisualExpression() : base()
{
SetRandomColor();
IsVisible = true;
}
public VisualExpression(string expr) : base(expr)
{
SetRandomColor();
IsVisible = true;
}
public VisualExpression(string expr, Color color, double thickness = 2) : base(expr)
{
this.Color = color;
this.Thickness = thickness;
IsVisible = true;
}
#endregion
public void SetRandomColor()
{
Random random = new Random(rand_seed);
rand_seed = 0x51 * (random.Next() - 0xA82F90) * random.Next() - 0x513511;
int r, g, b;
r = random.Next(256);
g = random.Next(256);
b = random.Next(256);
int avg = (r + g + b) / 3;
int min = Math.Min(r, Math.Min(g, b));
if (avg >= 182) {
r -= min; g -= min; b -= min;
}
this.Color = Color.FromRgb(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b));
}
}
}