-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGradientStopCollectionExtension.cs
More file actions
35 lines (29 loc) · 1.39 KB
/
Copy pathGradientStopCollectionExtension.cs
File metadata and controls
35 lines (29 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Windows.Media;
namespace CSharpCodeAnalyst.TreeMap.Drawing
{
public static class GradientStopCollectionExtensions
{
public static Color GetRelativeColor(this GradientStopCollection gsc, double offset)
{
var before = gsc.First(w => w.Offset == gsc.Min(m => m.Offset));
var after = gsc.First(w => w.Offset == gsc.Max(m => m.Offset));
foreach (var gs in gsc)
{
if (gs.Offset < offset && gs.Offset > before.Offset)
{
before = gs;
}
if (gs.Offset > offset && gs.Offset < after.Offset)
{
after = gs;
}
}
var color = new Color();
color.ScA = (float) ((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA);
color.ScR = (float) ((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR);
color.ScG = (float) ((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG);
color.ScB = (float) ((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB);
return color;
}
}
}