-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate random colors for highlights
- Loading branch information
Showing
4 changed files
with
86 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Avalonia.Media; | ||
|
||
namespace LogAlligator.App.Utils; | ||
|
||
public class HighlightColorProvider(Random? random = null) | ||
{ | ||
private Random _random = random ?? Random.Shared; | ||
|
||
public Color GetHighlightColor() | ||
{ | ||
return GetRandomColor(); | ||
} | ||
|
||
private Color GetRandomColor() | ||
{ | ||
double hue = GetHue(); | ||
double saturation = 1.0; | ||
double lightness = GetLightness(); | ||
|
||
return HslColor.ToRgb(hue * 360, saturation, lightness); | ||
} | ||
|
||
private double GetHue() | ||
{ | ||
return _random.NextDouble(); | ||
} | ||
|
||
private double GetLightness() | ||
{ | ||
return RandomBetween(0.1, 0.9); | ||
} | ||
|
||
private double RandomBetween(double min, double max) | ||
{ | ||
return min + _random.NextDouble() * (max - min); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters