First commit

This commit is contained in:
thepra 2017-03-02 13:36:26 +01:00
parent 61be829653
commit 1029ea6fc7
7 changed files with 1610 additions and 0 deletions

20
ColGen.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColGen", "ColGen\ColGen.csproj", "{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

6
ColGen/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

65
ColGen/ColGen.csproj Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B5240A73-56EE-44C1-88BE-BDD99DA3AC71}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ColGen</RootNamespace>
<AssemblyName>ColGen</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="func.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Include="HSL.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

296
ColGen/HSL.cs Normal file
View File

@ -0,0 +1,296 @@
//----------------------------------------------------------------------
// Namespace Christo.GFX.Conversion
// Author: Christo Greeff
// Date: 24/June/2008
//----------------------------------------------------------------------
// 24/June/2008 : New: GFXConversionException, HSL
//----------------------------------------------------------------------
using System;
using System.Drawing;
namespace Christo.GFX.Conversion
{
/// <summary>
/// Color Util Exception
/// </summary>
public class GFXConversionException : Exception
{
public GFXConversionException(string message, Exception innerException)
: base(message, innerException)
{
//ToDo: Implement if needed
}
}
/// <summary>
/// HSL (Hue/Saturation/Luminance) Class
/// </summary>
public class HSL
{
#region Private members
/// <summary>
/// private hue
/// </summary>
private double _h;
/// <summary>
/// private saturation
/// </summary>
private double _s;
/// <summary>
/// private luminance
/// </summary>
private double _l;
#endregion
/// <summary>
/// Constructor
/// </summary>
public HSL()
{
try
{
this.HSLHelper(0, 0, 0);
}
catch (Exception ee)
{
throw new GFXConversionException("HSL Constructor Error", ee);
}
}
/// <summary>
/// Constructor with ARGB color
/// </summary>
/// <param name="color">System.Drawing.Color value</param>
public HSL(Color color)
{
try
{
this.HSLHelper(color.GetHue() / 360.0, color.GetSaturation(), color.GetBrightness());
}
catch (Exception ee)
{
throw new GFXConversionException("HSL Constructor Error", ee);
}
}
/// <summary>
/// Constructor with RGB color
/// </summary>
/// <param name="R">Red component with a value from 0 to 255</param>
/// <param name="G">Green component with a value from 0 to 255</param>
/// <param name="B">Blue component with a value from 0 to 255</param>
public HSL(byte R, byte G, byte B)
{
try
{
Color temp = Color.FromArgb(R, G, B);
this.HSLHelper(temp.GetHue() / 360.0, temp.GetSaturation(), temp.GetBrightness());
}
catch (Exception ee)
{
throw new GFXConversionException("HSL Constructor Error", ee);
}
}
/// <summary>
/// Constructor with HSL
/// </summary>
/// <param name="Hue">Varies from magenta - red - yellow - green - cyan - blue - magenta, described as an angle around a circle from 0.0 - 360.0 degrees</param>
/// <param name="Saturation">Varies from 0.0 and 1.0 and describes how "grey" the colour is, with 0 being completely unsaturated (grey, white or black) and 1 being completely saturated</param>
/// <param name="Luminance">Varies from 0.0 and 1.0 and ranges from black at 0.0, through the standard colour itself at 0.5 to white at 1.0</param>
public HSL(double Hue, double Saturation, double Luminance)
{
try
{
this.HSLHelper(Hue, Saturation, Luminance);
}
catch (Exception ee)
{
throw new GFXConversionException("HSL Constructor Error", ee);
}
}
/// <summary>
/// HSL Helper
/// </summary>
/// <param name="Hue">Varies from magenta - red - yellow - green - cyan - blue - magenta, described as an angle around a circle from 0.0 - 360.0 degrees</param>
/// <param name="Saturation">Varies from 0.0 and 1.0 and describes how "grey" the colour is, with 0 being completely unsaturated (grey, white or black) and 1 being completely saturated</param>
/// <param name="Luminance">Varies from 0.0 and 1.0 and ranges from black at 0.0, through the standard colour itself at 0.5 to white at 1.0</param>
private void HSLHelper(double Hue, double Saturation, double Luminance)
{
try
{
this.H = Hue;
this.S = Saturation;
this.L = Luminance;
}
catch (Exception ee)
{
throw new GFXConversionException("HSL HSLHelper Error", ee);
}
}
/// <summary>
/// Set helper function
/// </summary>
/// <param name="value">value that must be between 0 and 1</param>
/// <returns>double value</returns>
private double SetHelper(double value)
{
try
{
return (value > 1) ? 1.0 : (value < 0) ? 0 : value;
}
catch (Exception ee)
{
throw new GFXConversionException("HSL SetHelper Error", ee);
}
}
/// <summary>
/// Gets or sets the Hue value
/// </summary>
public double H
{
get
{
return this._h;
}
set
{
this._h = this.SetHelper(value);
}
}
/// <summary>
/// Gets or sets the Saturation value
/// </summary>
public double S
{
get
{
return this._s;
}
set
{
this._s = this.SetHelper(value);
}
}
/// <summary>
/// Gets or sets the Luminance value
/// </summary>
public double L
{
get
{
return this._l;
}
set
{
this._l = this.SetHelper(value);
}
}
/// <summary>
/// <para>Convert from the current HSL to RGB</para>
/// <para>http://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_HSL_to_RGB</para>
/// </summary>
public Color Color
{
get
{
double[] t = new double[] { 0, 0, 0 };
try
{
double tH = this._h;
double tS = this._s;
double tL = this._l;
if (tS.Equals(0))
{
t[0] = t[1] = t[2] = tL;
}
else
{
double q, p;
q = tL < 0.5 ? tL * (1 + tS) : tL + tS - (tL * tS);
p = 2 * tL - q;
t[0] = tH + (1.0 / 3.0);
t[1] = tH;
t[2] = tH - (1.0 / 3.0);
for (byte i = 0; i < 3; i++)
{
t[i] = t[i] < 0 ? t[i] + 1.0 : t[i] > 1 ? t[i] - 1.0 : t[i];
if (t[i] * 6.0 < 1.0)
t[i] = p + ((q - p) * 6 * t[i]);
else
if (t[i] * 2.0 < 1.0)
t[i] = q;
else
if (t[i] * 3.0 < 2.0)
t[i] = p + ((q - p) * 6 * ((2.0 / 3.0) - t[i]));
else
t[i] = p;
}
}
}
catch (Exception ee)
{
throw new GFXConversionException("HSL Color Error", ee);
}
return Color.FromArgb((int)(t[0] * 255), (int)(t[1] * 255), (int)(t[2] * 255));
}
}
/// <summary>
/// Modify the current HSL brightness
/// </summary>
/// <param name="brightness">brightness value</param>
/// <returns>HSL</returns>
private HSL BrightnessHelper(double brightness)
{
try
{
this.L = this.L * brightness;
}
catch (Exception ee)
{
throw new GFXConversionException("HSL BrightnessHelper Error", ee);
}
return new HSL(H, S, L);
}
/// <summary>
/// Modify the current HSL brightness
/// </summary>
/// <param name="brightness">brightness value</param>
/// <returns>HSL</returns>
public HSL Brightness(double brightness)
{
return this.BrightnessHelper(brightness);
}
/// <summary>
/// Modify the current HSL brightness
/// </summary>
/// <param name="brightness">brightness value</param>
/// <returns>Color</returns>
public Color BrightnessC(double brightness)
{
return this.BrightnessHelper(brightness).Color;
}
}
}

430
ColGen/Program.cs Normal file
View File

@ -0,0 +1,430 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ColGen
{
class Program
{
static void Main(string[] args)
{
Program z = new Program();
int choice,version;
List<string> traits = new List<string>();
List<string> options = new List<string>
{
"1)Uniform",
"2)RandomWalk",
"3)RandomMix",
"4)RandomMix",
"5)RandomMix",
"6)RandomMix",
"7)RandomMix",
"8)RandomMix",
"9)RandomAdd",
"10)RandomAdd",
"11)RandomAdd",
"12)Offset",
"13)Hue",
"14)Saturation",
"15)Luminance",
"16)SaturationLuminance",
"17)GoldenRatioRainbow",
"18)GoldenRatioGradient",
"19)JitteredRainbow",
"20)JitteredRainbow",
"21)JitteredRainbow",
"22)HueRange",
"23)Harmony",
"24)Harmony2"
};
foreach (var option in options)
{
Console.WriteLine(option);
}
choice = int.Parse(Console.ReadLine());
Console.WriteLine("Version?(if any)");
version = int.Parse(Console.ReadLine());
for (int i = 0; i < 4; i++)
{
if (i % 2 == 0)
{
var rand1 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type1(z.ToSingleColour(rand1,choice,version)));
Thread.Sleep(100);
var rand2 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type2(z.ToSingleColour(rand2, choice, version)));
Thread.Sleep(100);
var rand3 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type1(z.ToSingleColour(rand3, choice, version)));
Thread.Sleep(100);
var rand4 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type2(z.ToSingleColour(rand4, choice, version)));
}
else
{
var rand1 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type3(z.ToSingleColour(rand1, choice, version)));
Thread.Sleep(100);
var rand2 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type4(z.ToSingleColour(rand2, choice, version)));
Thread.Sleep(100);
var rand3 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type3(z.ToSingleColour(rand3, choice, version)));
Thread.Sleep(100);
var rand4 = new Random(DateTime.Now.Millisecond);
traits.Add(z.Type4(z.ToSingleColour(rand4, choice, version)));
}
}
if (File.Exists("html.txt"))
File.Delete("html.txt");
File.AppendAllLines("html.txt", traits);
Console.WriteLine("DONE");
Console.ReadLine();
}
public string ToSingleColour(Random rand,int choice,int version)
{
string colour, temp;
Color a = this.GetColour(rand,choice,version);
temp = a.Name;
colour = "#" + temp.Substring(2, 6);
return colour;
}
public string RandColor(Random rand)
{
double offset = 1.0;
double value = (rand.Next(0, 255) + rand.Next(0, 255) + rand.Next(0, 255)) / 3;
double value2 = (rand.Next(0, 255) + rand.Next(0, 255) + rand.Next(0, 255)) / 3;
double value3 = (rand.Next(0, 255) + rand.Next(0, 255) + rand.Next(0, 255)) / 3;
double newValue = value + 2 * rand.Next() * offset - offset;
double valueRatio = (newValue / value);
var color = String.Format("#FA{0:X2}01", rand.Next(0, 255)/*, rand.Next(0, 255), rand.Next(0, 255)*/);
return color;
}
public string Type1(string onlyColor)
{
//string onlyColor = this.RandColor(rand);
string type1 = string.Format("<div id=\"Trait1\" style=\"box-shadow:5px 5px 5px 0 {0}\">\n", onlyColor);
type1 = string.Concat(type1, "\t<table id=\"table\">\n");
type1 = string.Concat(type1, "\t\t<tr><th colspan=\"2\">TraitName</th></tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBL iRTR pdd2 bgColorGray\">Sincere:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTL iRBR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"iRTLl inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"0\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRTL pdd2 bgColorGray\">Dissimulated:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"100\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBLb pdd2 bgColorGray\">Opinion:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"pdd0\">\n");
type1 = string.Concat(type1, "\t\t\t\t<select name=\"selection\" class=\"bSN selFix\">\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"positive\">Positive</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"neutral\">Neutral</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"negative\">Negative</option>\n");
type1 = string.Concat(type1, "\t\t\t\t</select>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t</table>\n");
type1 = string.Concat(type1, "</div>");
return type1;
}
public string Type2(string onlyColor)
{
//string onlyColor = this.RandColor(rand);
string type1 = string.Format("<div id=\"Trait2\" style=\"box-shadow:-5px 5px 5px 0 {0}\">\n", onlyColor);
type1 = string.Concat(type1, "\t<table id=\"table\">\n");
type1 = string.Concat(type1, "\t\t<tr><th colspan=\"2\">TraitName</th></tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBL iRTR pdd2 bgColorGray\">Sincere:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTL iRBR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"iRTLl inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"0\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRTL pdd2 bgColorGray\">Dissimulated:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"100\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight pdd2 bgColorGray\">Opinion:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"pdd0\">\n");
type1 = string.Concat(type1, "\t\t\t\t<select name=\"selection\" class=\"bSN iRBRb selFix\">\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"positive\">Positive</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"neutral\">Neutral</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"negative\">Negative</option>\n");
type1 = string.Concat(type1, "\t\t\t\t</select>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t</table>\n");
type1 = string.Concat(type1, "</div>");
return type1;
}
public string Type3(string onlyColor)
{
//string onlyColor = this.RandColor(rand);
string type1 = string.Format("<div id=\"Trait3\" style=\"box-shadow:5px -5px 5px 0 {0}\">\n", onlyColor);
type1 = string.Concat(type1, "\t<table id=\"table\">\n");
type1 = string.Concat(type1, "\t\t<tr><th colspan=\"2\">TraitName</th></tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBL iRTR pdd2 bgColorGray\">Sincere:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTL iRBR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"iRTLl inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"0\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRTL pdd2 bgColorGray\">Dissimulated:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"100\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight pdd2 bgColorGray\">Opinion:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"pdd0\">\n");
type1 = string.Concat(type1, "\t\t\t\t<select name=\"selection\" class=\"bSN iRBRb selFix\">\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"positive\">Positive</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"neutral\">Neutral</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"negative\">Negative</option>\n");
type1 = string.Concat(type1, "\t\t\t\t</select>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t</table>\n");
type1 = string.Concat(type1, "</div>");
return type1;
}
public string Type4(string onlyColor)
{
//string onlyColor = this.RandColor(rand);
string type1 = string.Format("<div id=\"Trait4\" style=\"box-shadow:-5px -5px 5px 0 {0}\">\n", onlyColor);
type1 = string.Concat(type1, "\t<table id=\"table\">\n");
type1 = string.Concat(type1, "\t\t<tr><th colspan=\"2\">TraitName</th></tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBL iRTR pdd2 bgColorGray\">Sincere:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTL iRBR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"iRTLl inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"0\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRTL pdd2 bgColorGray\">Dissimulated:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"iRTR bgColorGray pdd3\">\n");
type1 = string.Concat(type1, string.Format("\t\t\t\t<input class=\"inWid\" name=\"True\" type=\"number\" max=\"100\" min=\"0\" value=\"100\" style=\"border: 1px solid {0};box-shadow: 0 0 7px 0 {0} inset\"><span class=\"fR\">(0-100)</span><br>\n", onlyColor));
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"true\" value=\"100\">True<span class=\"fR\">(100)</span><br>\n");
type1 = string.Concat(type1, "\t\t\t\t<input type=\"radio\" name=\"false\" value=\"0\">False<span class=\"fR\">(0)</span>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t\t<tr>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"toRight iRBLb pdd2 bgColorGray\">Opinion:</td>\n");
type1 = string.Concat(type1, "\t\t\t<td class=\"pdd0\">\n");
type1 = string.Concat(type1, "\t\t\t\t<select name=\"selection\" class=\"bSN selFix\">\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"positive\">Positive</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"neutral\">Neutral</option>\n");
type1 = string.Concat(type1, "\t\t\t\t\t<option value=\"negative\">Negative</option>\n");
type1 = string.Concat(type1, "\t\t\t\t</select>\n");
type1 = string.Concat(type1, "\t\t\t</td>\n");
type1 = string.Concat(type1, "\t\t</tr>\n");
type1 = string.Concat(type1, "\t</table>\n");
type1 = string.Concat(type1, "</div>");
return type1;
}
public Color GetColour(Random random, int outerSel = 1, int version = 0)
{
//random = new Random(15);//15
//Random random = new Random(12);//15
Color color = new Color();
//int versionCount = 3;
int colorCount = 1;
//int imageWidth = 680;
//int imageHeight = 100;
//int spacing = 2;
Color[] baseColors = {
Color.FromArgb(255, 128, 0),
Color.FromArgb(128, 255, 64),
Color.FromArgb(64, 128, 255)};
float[] saturation = { 1.0f, 0.7f, 0.3f };
float[] luminance = { 0.45f, 0.7f, 0.4f };
float[] hueStart = { 0.9f, 0.2f, 0.6f };
float[] hueEnd = { 0.1f, 0.5f, 0.9f };
Color[] mixColor1 =
{
Color.FromArgb(255, 0, 33),
Color.FromArgb(255, 100, 33),
Color.FromArgb(128, 0, 33),
};
Color[] mixColor2 =
{
Color.FromArgb(255, 255, 0),
Color.FromArgb(255, 255, 100),
Color.FromArgb(255, 128, 0),
};
Color[] mixColor3 =
{
Color.FromArgb(0, 100, 255),
Color.FromArgb(100, 150, 255),
Color.FromArgb(0, 80, 128),
};
Color[] addColor1 =
{
Color.FromArgb(150, 0, 0),
Color.FromArgb(200, 20, 0),
Color.FromArgb(128, 0, 33),
};
Color[] addColor2 =
{
Color.FromArgb(0, 150, 0),
Color.FromArgb(200, 200, 20),
Color.FromArgb(255, 128, 0),
};
Color[] addColor3 =
{
Color.FromArgb(0, 0, 150),
Color.FromArgb(20, 20, 200),
Color.FromArgb(0, 80, 128),
};
Color[][] gradients =
{
new Color[]
{
Color.FromArgb(255, 0, 128),
Color.FromArgb(255, 255, 0),
Color.FromArgb(0, 255, 255),
},
new Color[]
{
Color.FromArgb(200, 0, 33),
Color.FromArgb(255, 200, 0),
Color.FromArgb(0, 100, 200),
},
new Color[]
{
Color.FromArgb(255, 0, 33),
Color.FromArgb(255, 255, 0),
Color.FromArgb(0, 255, 0),
Color.FromArgb(255, 255, 0),
}
};
float[] offsetAngles1 = { 15, 180, 120 };
float[] offsetAngles2 = { 30, 0, 240 };
float[] angleRanges1 = { 15, 40f, 40 };
float[] angleRanges2 = { 15, 40f, 40 };
float[] angleRanges3 = { 15, 0, 40 };
switch (outerSel)
{
case 1:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_Uniform(colorCount).First(); } break;
case 2:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomWalk(colorCount, baseColors[version], 0.2f, 0.4f).First(); } break;
case 3:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.1f, true).First(); } break;
case 4:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.5f, true).First(); } break;
case 5:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.9f, true).First(); } break;
case 6:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.1f, false).First(); } break;
case 7:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.5f, false).First(); } break;
case 8:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.9f, false).First(); } break;
case 9:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.1f).First(); } break;
case 10:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.5f).First(); } break;
case 11:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.9f).First(); } break;
case 12:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_Offset(colorCount, baseColors[version], 0.4f).First(); } break;
case 13:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_Hue(colorCount, saturation[version], luminance[version]).First(); } break;
case 14:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_Saturation(colorCount, hueStart[version], luminance[version]).First(); } break;
case 15:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_Luminance(colorCount, hueStart[version], saturation[version]).First(); } break;
case 16:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_SaturationLuminance(colorCount, hueStart[version]).First(); } break;
case 17:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_GoldenRatioRainbow(colorCount, saturation[version], luminance[version]).First(); } break;
case 18:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_GoldenRatioGradient(colorCount, gradients[0], saturation[0], luminance[0]).First(); } break;
case 19:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_JitteredRainbow(colorCount, 0, 1, saturation[version], luminance[version], true).First(); } break;
case 20:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_JitteredRainbow(colorCount, hueStart[version], hueEnd[version], saturation[version], luminance[version], true).First(); } break;
case 21:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_JitteredRainbow(colorCount, 0, 1, saturation[version], luminance[version], false).First(); } break;
case 22:
{ color = ProceduralPalette.ProceduralPalette.GenerateColors_HueRange(colorCount, hueStart[version], hueEnd[version], saturation[version], luminance[version]).First(); } break;
case 23:
{
color = ProceduralPalette.ProceduralPalette.GenerateColors_Harmony(colorCount,
offsetAngles1[version], offsetAngles2[version],
angleRanges1[version], angleRanges2[version], angleRanges3[version],
saturation[version], luminance[version]).First();
} break;
case 24:
{
color = ProceduralPalette.ProceduralPalette.GenerateColors_Harmony2(colorCount,
offsetAngles1[version], offsetAngles2[version],
angleRanges1[version], angleRanges2[version], angleRanges3[version],
saturation[version], 0.2f,
luminance[version], 0.5f).First();
} break;
default:
break;
}
return color;
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ColGen")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColGen")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fac98cd8-dbc0-4d93-899c-4105aebde85e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

757
ColGen/func.cs Normal file
View File

@ -0,0 +1,757 @@
/**
This is tutorial code that goes with the article http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using Christo.GFX.Conversion;
namespace ProceduralPalette
{
public static class RandomExtensions
{
public static int NextByte(this Random random)
{
return ProceduralPalette.FloatToByte(random.NextDouble());
}
public static float NextFloat(this Random random)
{
return (float) random.NextDouble();
}
}
class ProceduralPalette
{
private static Random random = new Random();
public static List<Color> GenerateColors_Uniform(int colorCount)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
Color newColor = Color.FromArgb(
255,
random.NextByte(),
random.NextByte(),
random.NextByte());
colors.Add(newColor);
}
return colors;
}
public static List<Color> GenerateColors_Harmony(
int colorCount,
float offsetAngle1,
float offsetAngle2,
float rangeAngle0,
float rangeAngle1,
float rangeAngle2,
float saturation, float luminance)
{
List<Color> colors = new List<Color>();
float referenceAngle = random.NextFloat() * 360;
for (int i = 0; i < colorCount; i++)
{
float randomAngle = random.NextFloat() * (rangeAngle0 + rangeAngle1 + rangeAngle2);
if (randomAngle > rangeAngle0)
{
if (randomAngle < rangeAngle0 + rangeAngle1)
{
randomAngle += offsetAngle1;
}
else
{
randomAngle += offsetAngle2;
}
}
HSL hslColor = new HSL(((referenceAngle + randomAngle) / 360.0f) % 1.0f, saturation, luminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_Harmony2(
int colorCount,
float offsetAngle1,
float offsetAngle2,
float rangeAngle0,
float rangeAngle1,
float rangeAngle2,
float saturation, float saturationRange,
float luminance, float luminanceRange)
{
List<Color> colors = new List<Color>();
float referenceAngle = random.NextFloat() * 360;
for (int i = 0; i < colorCount; i++)
{
float randomAngle = random.NextFloat() * (rangeAngle0 + rangeAngle1 + rangeAngle2);
if (randomAngle > rangeAngle0)
{
if (randomAngle < rangeAngle0 + rangeAngle1)
{
randomAngle += offsetAngle1;
}
else
{
randomAngle += offsetAngle2;
}
}
float newSaturation = saturation + (random.NextFloat() - 0.5f) * saturationRange;
float newLuminance = luminance + +(random.NextFloat() - 0.5f) * luminanceRange;
HSL hslColor = new HSL(((referenceAngle + randomAngle) / 360.0f) % 1.0f, newSaturation, newLuminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_RandomWalk(int colorCount, Color startColor, float min, float max)
{
List<Color> colors = new List<Color>();
Color newColor = startColor;
float range = max - min;
for (int i = 0; i < colorCount; i++)
{
int rSign = random.Next(2) % 2 == 0 ? 1 : -1;
int gSign = random.Next(2) % 2 == 0 ? 1 : -1;
int bSign = random.Next(2) % 2 == 0 ? 1 : -1;
newColor = Color.FromArgb(
255,
FloatToByte(ByteToFloat(newColor.R) + rSign * (min + random.NextDouble() * range)),
FloatToByte(ByteToFloat(newColor.G) + rSign * (min + random.NextDouble() * range)),
FloatToByte(ByteToFloat(newColor.B) + rSign * (min + random.NextDouble() * range)));
colors.Add(newColor);
}
return colors;
}
public static List<Color> GenerateColors_RandomMix(int colorCount, Color color1, Color color2, Color color3, float greyControl, bool paint)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
Color newColor;
if (paint)
{
newColor = RandomMixHSL(color1, color2, color3, greyControl);
}
else
{
newColor = RandomMix(color1, color2, color3, greyControl);
}
colors.Add(newColor);
}
return colors;
}
public static List<Color> GenerateColors_RandomAdd(int colorCount, Color color1, Color color2, Color color3, float nonGrayBias)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
Color newColor = RandomAdd(color1, color2, color3, nonGrayBias);
colors.Add(newColor);
}
return colors;
}
public static List<Color> GenerateColors_Offset(int colorCount, Color color, float maxRange)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
Color newColor = Color.FromArgb(
255,
FloatToByte((ByteToFloat(color.R) + random.NextDouble() * 2 * maxRange - maxRange)),
FloatToByte((ByteToFloat(color.G) + random.NextDouble() * 2 * maxRange - maxRange)),
FloatToByte((ByteToFloat(color.B) + random.NextDouble() * 2 * maxRange - maxRange)));
colors.Add(newColor);
}
return colors;
}
public static List<Color> GenerateColors_Hue(int colorCount, float saturation, float luminance)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(random.NextDouble(), saturation, luminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_Saturation(int colorCount, float hue, float luminance)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(hue, random.NextDouble(), luminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_Luminance(int colorCount, float hue, float saturation)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(hue, saturation, random.NextDouble());
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_SaturationLuminance(int colorCount, float hue)
{
List<Color> colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(hue, random.NextDouble(), random.NextDouble());
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_GoldenRatioRainbow(int colorCount, float saturation, float luminance)
{
List<Color> colors = new List<Color>();
float goldenRatioConjugate = 0.618033988749895f;
float currentHue = (float) random.NextDouble();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(currentHue, saturation, luminance);
colors.Add(hslColor.Color);
currentHue += goldenRatioConjugate;
currentHue %= 1.0f;
}
return colors;
}
public static List<Color> GenerateColors_GoldenRatioGradient(int colorCount, Color[] gradient, float saturation, float luminance)
{
List<Color> colors = new List<Color>();
float goldenRatioConjugate = 0.618033988749895f;
float currentHue = (float)random.NextDouble();
for (int i = 0; i < colorCount; i++)
{
HSL hslColor = new HSL(currentHue, saturation, luminance);
Color newColor = SampleLinearGradient(gradient, currentHue);
colors.Add(newColor);
currentHue += goldenRatioConjugate;
currentHue %= 1.0f;
}
return colors;
}
public static List<Color> GenerateColors_HueRange(int colorCount, float startHue, float endHue, float saturation, float luminance)
{
List<Color> colors = new List<Color>();
float hueRange = endHue - startHue;
if(hueRange < 0)
{
hueRange += 1.0f;
}
for (int i = 0; i < colorCount; i++)
{
float newHue = (float) (hueRange * random.NextDouble() + startHue);
if(newHue > 1.0)
{
newHue -= 1.0f;
}
HSL hslColor = new HSL(newHue, saturation, luminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static List<Color> GenerateColors_JitteredRainbow(int colorCount, float startHue, float endHue, float saturation, float luminance, bool jitter)
{
List<Color> colors = new List<Color>();
float hueRange = endHue - startHue;
if (hueRange < 0)
{
hueRange = 1 + hueRange;
}
float cellRange = hueRange / colorCount;
float cellOffset = (float) (random.NextDouble() * cellRange);
for (int i = 0; i < colorCount; i++)
{
float newHue;
if (jitter)
{
newHue = (float)(cellRange * i + random.NextDouble() * cellRange + startHue);
}
else
{
newHue = (cellRange * i + cellOffset + startHue);
}
if(newHue > 1)
{
newHue -= 1.0f;
}
HSL hslColor = new HSL(newHue, saturation, luminance);
colors.Add(hslColor.Color);
}
return colors;
}
public static int FloatToByte(double value)
{
int byteValue = (int)(value * 256);
byteValue = SaturateByte(byteValue);
return byteValue;
}
private static int SaturateByte(int byteValue)
{
if (byteValue > 255)
{
byteValue = 255;
}
else if (byteValue < 0)
{
byteValue = 0;
}
return byteValue;
}
public static float ByteToFloat(int byteValue)
{
float floatValue = byteValue / 256.0f;
return floatValue;
}
public static Color RandomMix(Color color1, Color color2, Color color3, float greyControl)
{
int randomIndex = random.NextByte() % 3;
float mixRatio1 = (randomIndex == 0) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio2 = (randomIndex == 1) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio3 = (randomIndex == 2) ? random.NextFloat() * greyControl : random.NextFloat();
float sum = mixRatio1 + mixRatio2 + mixRatio3;
mixRatio1 /= sum;
mixRatio2 /= sum;
mixRatio3 /= sum;
return Color.FromArgb(
255,
(byte)(mixRatio1 * color1.R + mixRatio2 * color2.R + mixRatio3 * color3.R),
(byte)(mixRatio1 * color1.G + mixRatio2 * color2.G + mixRatio3 * color3.G),
(byte)(mixRatio1 * color1.B + mixRatio2 * color2.B + mixRatio3 * color3.B));
}
public static Color RandomMixHSL(Color color1, Color color2, Color color3, float greyControl)
{
int randomIndex = random.NextByte() % 3;
float mixRatio1 = (randomIndex == 0) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio2 = (randomIndex == 1) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio3 = (randomIndex == 2) ? random.NextFloat() * greyControl : random.NextFloat();
float sum = mixRatio1 + mixRatio2 + mixRatio3;
mixRatio1 /= sum;
mixRatio2 /= sum;
mixRatio3 /= sum;
HSL hsl1 = new HSL(color1);
HSL hsl2 = new HSL(color2);
HSL hsl3 = new HSL(color3);
return new HSL(
(mixRatio1 * hsl1.H + mixRatio2 * hsl2.H + mixRatio3 * hsl3.H),
(mixRatio1 * hsl1.S + mixRatio2 * hsl2.S + mixRatio3 * hsl3.S),
(mixRatio1 * hsl1.L + mixRatio2 * hsl2.L + mixRatio3 * hsl3.L)).Color;
}
public static Color RandomMixPaint(Color color1, Color color2, Color color3, float greyControl)
{
int randomIndex = random.NextByte() % 3;
float mixRatio1 = (randomIndex == 0) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio2 = (randomIndex == 1) ? random.NextFloat() * greyControl : random.NextFloat();
float mixRatio3 = (randomIndex == 2) ? random.NextFloat() * greyControl : random.NextFloat();
float sum = mixRatio1 + mixRatio2 + mixRatio3;
mixRatio1 /= sum;
mixRatio2 /= sum;
mixRatio3 /= sum;
return Color.FromArgb(
255,
255 - (byte)(mixRatio1 * (255 - color1.R) + mixRatio2 * (255 - color2.R) + mixRatio3 * (255 - color3.R)),
255 - (byte)(mixRatio1 * (255 - color1.G) + mixRatio2 * (255 - color2.G) + mixRatio3 * (255 - color3.G)),
255 - (byte)(mixRatio1 * (255 - color1.B) + mixRatio2 * (255 - color2.B) + mixRatio3 * (255 - color3.B)));
}
public static Color RandomAdd(Color color1, Color color2, Color color3, float nonGrayBias)
{
int rIndex = random.NextByte() % 3;
float r1 = (rIndex == 0) ? random.NextFloat() * nonGrayBias : random.NextFloat();
float r2 = (rIndex == 1) ? random.NextFloat() * nonGrayBias : random.NextFloat();
float r3 = (rIndex == 2) ? random.NextFloat() * nonGrayBias : random.NextFloat();
float p = 20;
float sum = (float) Math.Pow(
Math.Pow(r1, p) +
Math.Pow(r2, p) +
Math.Pow(r3, p), 1 / p);
r1 /= sum;
r2 /= sum;
r3 /= sum;
return Color.FromArgb(
255,
SaturateToByte(r1 * color1.R + r2 * color2.R + r3 * color3.R),
SaturateToByte(r1 * color1.G + r2 * color2.G + r3 * color3.G),
SaturateToByte(r1 * color1.B + r2 * color2.B + r3 * color3.B));
}
public static int SaturateToByte(float floatValue)
{
int intValue = (int)floatValue;
if (intValue > 255)
{
intValue = 255;
}
else if( intValue < 0)
{
intValue = 0;
}
return intValue;
}
public static Color SampleLinearGradient(Color [] colors, float t)
{
int colorCount = colors.Length;
int leftIndex = (int) (t * colorCount);
float cellRange = 1.0f / colorCount;
float alpha = (t - leftIndex * cellRange) / cellRange;
Color leftColor = colors[leftIndex];
Color rightColor = colors[(leftIndex + 1) % colorCount];
return Color.FromArgb(
255,
(byte) (leftColor.R * (1 - alpha) + rightColor.R * (alpha)),
(byte) (leftColor.G * (1 - alpha) + rightColor.G * (alpha)),
(byte) (leftColor.B * (1 - alpha) + rightColor.B * (alpha)));
}
public static Bitmap GeneratePaletteImage(List<Color> colors, int width, int height, int spacing)
{
Bitmap image = new Bitmap(width, height);
int colorCount = colors.Count;
int blockWidth = (width - ((colorCount - 1) * spacing)) / colorCount;
for (int i = 0; i < colorCount; i++)
{
DrawBlock(image, i * (blockWidth + spacing), 0, blockWidth, height, colors[i]);
}
return image;
}
public static void DrawBlock(Bitmap image, int x, int y, int width, int height, Color color)
{
for (int i = x; i < x + width; i++)
{
for (int j = y; j < y + height; j++)
{
image.SetPixel(i, j, color);
}
}
}
//static void Main(string[] args)
//{
// //random = new Random(15);//15
// random = new Random(12);//15
// List<Color> colors;
// int versionCount = 3;
// int colorCount = 20;
// int imageWidth = 680;
// int imageHeight = 100;
// int spacing = 2;
// Color[] baseColors = {
// Color.FromArgb(255, 128, 0),
// Color.FromArgb(128, 255, 64),
// Color.FromArgb(64, 128, 255)};
// float[] saturation = {1.0f, 0.7f, 0.3f};
// float[] luminance = {0.45f, 0.7f, 0.4f};
// float[] hueStart = {0.9f, 0.2f, 0.6f };
// float[] hueEnd = { 0.1f, 0.5f, 0.9f };
// Color[] mixColor1 =
// {
// Color.FromArgb(255, 0, 33),
// Color.FromArgb(255, 100, 33),
// Color.FromArgb(128, 0, 33),
// };
// Color[] mixColor2 =
// {
// Color.FromArgb(255, 255, 0),
// Color.FromArgb(255, 255, 100),
// Color.FromArgb(255, 128, 0),
// };
// Color[] mixColor3 =
// {
// Color.FromArgb(0, 100, 255),
// Color.FromArgb(100, 150, 255),
// Color.FromArgb(0, 80, 128),
// };
// Color[] addColor1 =
// {
// Color.FromArgb(150, 0, 0),
// Color.FromArgb(200, 20, 0),
// Color.FromArgb(128, 0, 33),
// };
// Color[] addColor2 =
// {
// Color.FromArgb(0, 150, 0),
// Color.FromArgb(200, 200, 20),
// Color.FromArgb(255, 128, 0),
// };
// Color[] addColor3 =
// {
// Color.FromArgb(0, 0, 150),
// Color.FromArgb(20, 20, 200),
// Color.FromArgb(0, 80, 128),
// };
// Color[][] gradients =
// {
// new Color[]
// {
// Color.FromArgb(255, 0, 128),
// Color.FromArgb(255, 255, 0),
// Color.FromArgb(0, 255, 255),
// },
// new Color[]
// {
// Color.FromArgb(200, 0, 33),
// Color.FromArgb(255, 200, 0),
// Color.FromArgb(0, 100, 200),
// },
// new Color[]
// {
// Color.FromArgb(255, 0, 33),
// Color.FromArgb(255, 255, 0),
// Color.FromArgb(0, 255, 0),
// Color.FromArgb(255, 255, 0),
// }
// };
// float[] offsetAngles1 =
// {
// 15, 180, 120
// };
// float[] offsetAngles2 =
// {
// 30, 0, 240
// };
// float[] angleRanges1 =
// {
// 15, 40f, 40
// };
// float[] angleRanges2 =
// {
// 15, 40f, 40
// };
// float[] angleRanges3 =
// {
// 15, 0, 40
// };
// for (int version = 0; version < versionCount; version++)
// {
// colors = GenerateColors_Uniform(colorCount);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Uniform_5_" + version + ".png");
// colors = GenerateColors_RandomWalk(colorCount, baseColors[version], 0.2f, 0.4f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("RandomWalk_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.1f, true);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("MixPaint1_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.5f, true);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("MixPaint5_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.9f, true);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("MixPaint9_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.1f, false);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Mix1_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.5f, false);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Mix5_5_" + version + ".png");
// colors = GenerateColors_RandomMix(colorCount, mixColor1[version], mixColor2[version], mixColor3[version], 0.9f, false);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Mix9_5_" + version + ".png");
// colors = GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.1f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Add1_5_" + version + ".png");
// colors = GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.5f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Add5_5_" + version + ".png");
// colors = GenerateColors_RandomAdd(colorCount, addColor1[version], addColor2[version], addColor3[version], 0.9f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Add9_5_" + version + ".png");
// colors = GenerateColors_Offset(colorCount, baseColors[version], 0.4f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Offset_5_" + version + ".png");
// colors = GenerateColors_Hue(colorCount, saturation[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Hue_5_" + version + ".png");
// colors = GenerateColors_Saturation(colorCount, hueStart[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Saturation_5_" + version + ".png");
// colors = GenerateColors_Luminance(colorCount, hueStart[version], saturation[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Luminance_5_" + version + ".png");
// colors = GenerateColors_SaturationLuminance(colorCount, hueStart[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Saturation_Luminance_5_" + version + ".png");
// colors = GenerateColors_GoldenRatioRainbow(colorCount, saturation[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("GoldenRatioRainbow_5_" + version + ".png");
// colors = GenerateColors_GoldenRatioGradient(colorCount, gradients[version], saturation[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("GoldenRatioGradient_5_" + version + ".png");
// colors = GenerateColors_JitteredRainbow(colorCount, 0, 1, saturation[version], luminance[version], true);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("JitteredRainbow_5_" + version + ".png");
// colors = GenerateColors_JitteredRainbow(colorCount, hueStart[version], hueEnd[version], saturation[version], luminance[version], true);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("JitteredRainbowRange_5_" + version + ".png");
// colors = GenerateColors_JitteredRainbow(colorCount, 0, 1, saturation[version], luminance[version], false);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Grid_Rainbow_5_" + version + ".png");
// colors = GenerateColors_HueRange(colorCount, hueStart[version], hueEnd[version], saturation[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("HueRange_5_" + version + ".png");
// colors = GenerateColors_Harmony(colorCount,
// offsetAngles1[version], offsetAngles2[version],
// angleRanges1[version], angleRanges2[version], angleRanges3[version],
// saturation[version], luminance[version]);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Harmony_5_" + version + ".png");
// colors = GenerateColors_Harmony2(colorCount,
// offsetAngles1[version], offsetAngles2[version],
// angleRanges1[version], angleRanges2[version], angleRanges3[version],
// saturation[version], 0.2f,
// luminance[version], 0.5f);
// GeneratePaletteImage(colors, imageWidth, imageHeight, spacing).Save("Harmony2_5_" + version + ".png");
// }
//}
}
}