© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
73 replies
~Eden

Splitting a number into equal distances (COMPLEX)

Okay the picture looks a little complicated so im going to try and explain it
I want to use HSL
HSL hue has a max value of 360

I want to divide this 360 to segments
In the code I chose 3 segments
So the first three value would be
0, 120, 240
(360 / 3), (360 / 3 * 1), (360 / 3 * 2)

Now I want to choose a 3 more colors
the best next set of unique colors are
60, 180, 300
(the middle of segment a) (middle seg b) (middle seg c)

now I want the next 3 unique colors
36 156 276
(the other side)

The yellow values are the next unique color
The purple is just a location value
lets say you want to find the Hue value for Yellow2 (first value for the second segment)
The purple value for it is 9
so its value is 9x12 (12 being 360/30 [where 30 is the amount of desired segments])

int segments = 30;
int degrees = 360;
int deg_per_line = degrees / segments;

var segmentation = 3;
double segmentDegrees = degrees / segmentation;

List<int> segmentList = new();

Console.WriteLine($"\n\n\n");

for (int i = 0; i < segmentation; i++)
{
    var val = i / (double)segmentation;
    segmentList.Add((int)Math.Ceiling(val * degrees));
}

// Loop until x is zero
for (int i = segments; i > 0; i -= segmentation)
{
    for (int e = 0; e < segmentation; e++)
        Console.Write(segmentList[e] + " ");

    // Calculate the remaining lines and the next slice
    int remaining_lines = i - segmentation;
    int next_slice = (int)Math.Ceiling((double)remaining_lines / segmentation / 2.0);

    if (remaining_lines % 2 == 0)
        next_slice -= 1;
//The following code is not correct maybe, its kind of a hack I got by trying random things
    else if (next_slice % 2 == 0)
        next_slice = next_slice * 2 -  1;

    // Accumulate the degrees for each slice
    for (int j = 0; j < segmentation; j++)
    {
        segmentList[j] = (int)(deg_per_line * next_slice + j * segmentDegrees);
    }

    Console.WriteLine();

    if (remaining_lines <= 0)
        return;
}
int segments = 30;
int degrees = 360;
int deg_per_line = degrees / segments;

var segmentation = 3;
double segmentDegrees = degrees / segmentation;

List<int> segmentList = new();

Console.WriteLine($"\n\n\n");

for (int i = 0; i < segmentation; i++)
{
    var val = i / (double)segmentation;
    segmentList.Add((int)Math.Ceiling(val * degrees));
}

// Loop until x is zero
for (int i = segments; i > 0; i -= segmentation)
{
    for (int e = 0; e < segmentation; e++)
        Console.Write(segmentList[e] + " ");

    // Calculate the remaining lines and the next slice
    int remaining_lines = i - segmentation;
    int next_slice = (int)Math.Ceiling((double)remaining_lines / segmentation / 2.0);

    if (remaining_lines % 2 == 0)
        next_slice -= 1;
//The following code is not correct maybe, its kind of a hack I got by trying random things
    else if (next_slice % 2 == 0)
        next_slice = next_slice * 2 -  1;

    // Accumulate the degrees for each slice
    for (int j = 0; j < segmentation; j++)
    {
        segmentList[j] = (int)(deg_per_line * next_slice + j * segmentDegrees);
    }

    Console.WriteLine();

    if (remaining_lines <= 0)
        return;
}
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

✅ splitting project into multiple files
C#CC# / help
3y ago
✅ Splitting string into chunks with delimiter
C#CC# / help
2y ago
❔ Entity logic splitting
C#CC# / help
4y ago