Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Last active April 25, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/86fdffdc92c9234796513b850771b277 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/86fdffdc92c9234796513b850771b277 to your computer and use it in GitHub Desktop.
Generate a rgb color from a hashcode
using System;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using HashcodeToColor;
namespace HashcodeToColor
{
class Program
{
static void Main(string[] args)
{
var source = ToHexColor("Employee".ToCharArray().Select(it => { return (int)it; }).Sum());
var color = (Color)new ColorConverter().ConvertFromString($"#{source}");
Console.WriteLine($"color is {color.GetHue()}");
Console.ReadLine();
}
static string ToHexColor(int i)
{
return ((i >> 24) & 0xFF).ToHex()
+ ((i >> 16) & 0xFF).ToHex()
+ ((i >> 8) & 0xFF).ToHex()
+ (i & 0xFF).ToHex();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment