Skip to content

Commit

Permalink
Better colors for random graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Oct 21, 2023
1 parent 3c3ed8f commit 45fe67d
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/BigRandom"
@implements IDisposable
@using KristofferStrube.Blazor.GraphEditor
@using System.Text;

<PageTitle>Blazor.GraphEditor - Big Random</PageTitle>

Expand Down Expand Up @@ -57,7 +58,25 @@
}
}

public string RandomColor() => $"#{Random.Shared.Next(255):X2}{Random.Shared.Next(255):X2}{Random.Shared.Next(255):X2}";
public string RandomColor()
{
float red = 0;
float green = 0;
float blue = 0;

while (Math.Abs(blue - green) + Math.Abs(blue - red) + Math.Abs(red - green) < 200)
{
red = Random.Shared.Next(0, 150);
green = Random.Shared.Next(0, 150);
blue = 225 - red - green;
}
if (blue > 150)
{
blue = 150;
}

return $"#{(int)(50 + red):X2}{(int)(50 + green):X2}{(int)(50 + blue):X2}";
}

public record Page(string id, string color = "#66BB6A", double size = 50, double repulsion = 800);
public record Transition(string from, string to, double weight, double length = 200);
Expand Down

0 comments on commit 45fe67d

Please sign in to comment.