private Random _rand = new Random();
private Color _lastMainStart;
private Color _lastMainEnd;
private Color _lastAccentsStart;
private Color _lastAccentsEnd;
private Color _lastTextColor;
private Color RandomColor(int min = 0, int max = 255)
{
return Color.FromArgb(
255,
_rand.Next(min, max + 1),
_rand.Next(min, max + 1),
_rand.Next(min, max + 1));
}
private Color RandomVibrantColor()
{
// Generate a vibrant color with high saturation and brightness via HSV conversion
double hue = _rand.NextDouble() * 360; // Hue between 0-360
double saturation = _rand.NextDouble() * 0.5 + 0.5; // Saturation between 0.5-1.0
double value = _rand.NextDouble() * 0.5 + 0.7; // Brightness between 0.7-1.0
return ColorFromHSV(hue, saturation, value);
}
private Color ColorFromHSV(double hue, double saturation, double value)
{
int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
double f = hue / 60 - Math.Floor(hue / 60);
value = Math.Max(0, Math.Min(1, value)); // clamp value to [0,1]
saturation = Math.Max(0, Math.Min(1, saturation)); // clamp saturation to [0,1]
hue = hue % 360; // hue in [0,360)
int v = Clamp((int)(value * 255), 0, 255);
int p = Clamp((int)(v * (1 - saturation)), 0, 255);
int q = Clamp((int)(v * (1 - f * saturation)), 0, 255);
int t = Clamp((int)(v * (1 - (1 - f) * saturation)), 0, 255);
return hi switch
{
0 => Color.FromArgb(255, v, t, p),
1 => Color.FromArgb(255, q, v, p),
2 => Color.FromArgb(255, p, v, t),
3 => Color.FromArgb(255, p, q, v),
4 => Color.FromArgb(255, t, p, v),
_ => Color.FromArgb(255, v, p, q),
};
}
private Color DarkenColor(Color color, float factor)
{
int r = (int)(color.R * (1 - factor));
int g = (int)(color.G * (1 - factor));
int b = (int)(color.B * (1 - factor));
return Color.FromArgb(255, Clamp(r, 0, 255), Clamp(g, 0, 255), Clamp(b, 0, 255));
}
private int Clamp(int val, int min, int max) => val < min ? min : (val > max ? max : val);
private enum ThemeStyle
{
Classic,
Vibrant,
Epic,
Neon,
Pastel,
DarkGlow,
Oceanic,
Sunset,
Cyberpunk,
Forest,
Retro,
Metallic,
Candy,
Space,
Vintage,
Aurora,
DarkRandom
}
private static int SafeRandomRange(Random rand, int minValue, int maxValue)
{
if (minValue > maxValue)
{
var temp = minValue;
minValue = maxValue;
maxValue = temp;
}
return rand.Next(minValue, maxValue + 1);
}
private Color RandomHueColor(int hMin, int hMax, double sMin, double sMax, double vMin, double vMax)
{
int hue = SafeRandomRange(_rand, hMin, hMax);
double saturation = _rand.NextDouble() * (sMax - sMin) + sMin;
double value = _rand.NextDouble() * (vMax - vMin) + vMin;
return ColorFromHSV(hue, saturation, value);
}
// Generate a unique color list helper with constraints
private List<Color> GenerateUniqueColors(int count, Func<Color> generator)
{
var set = new HashSet<int>();
var colors = new List<Color>();
int attempts = 0;
while (colors.Count < count && attempts < 1000)
{
Color c = generator();
int key = (c.R << 16) | (c.G << 8) | c.B;
if (!set.Contains(key))
{
set.Add(key);
colors.Add(c);
}
attempts++;
}
// Fallback fill if not enough unique colors found
while (colors.Count < count)
{
colors.Add(Color.FromArgb(255, _rand.Next(20), _rand.Next(20), _rand.Next(20)));
}
return colors;
}
private void GenerateRandomTheme(bool reapply = false)
{
if (!reapply || _lastMainStart == Color.Empty)
{
var style = (ThemeStyle)_rand.Next(Enum.GetValues(typeof(ThemeStyle)).Length);
switch (style)
{
case ThemeStyle.Classic:
_lastMainStart = RandomColor(10, 60);
_lastMainEnd = RandomColor(30, 100);
_lastAccentsStart = RandomColor(150, 255);
_lastAccentsEnd = RandomColor(100, 200);
_lastTextColor = RandomColor(200, 255);
break;
case ThemeStyle.Vibrant:
_lastMainStart = RandomVibrantColor();
_lastMainEnd = RandomVibrantColor();
_lastAccentsStart = RandomVibrantColor();
_lastAccentsEnd = RandomVibrantColor();
_lastTextColor = Color.White;
break;
case ThemeStyle.Epic:
_lastMainStart = RandomHueColor(0, 360, 0.7, 0.9, 0.1, 0.3);
_lastMainEnd = RandomHueColor(0, 360, 0.7, 0.9, 0.4, 0.6);
_lastAccentsStart = RandomHueColor(0, 360, 0.8, 1.0, 0.8, 1.0);
_lastAccentsEnd = RandomHueColor(0, 360, 0.6, 0.8, 0.6, 0.8);
_lastTextColor = Color.WhiteSmoke;
break;
case ThemeStyle.Neon:
_lastMainStart = Color.Black;
_lastMainEnd = Color.FromArgb(255, SafeRandomRange(_rand, 50, 90), SafeRandomRange(_rand, 0, 50), SafeRandomRange(_rand, 80, 255));
_lastAccentsStart = RandomHueColor(260, 300, 0.9, 1.0, 0.9, 1.0);
_lastAccentsEnd = RandomHueColor(130, 170, 0.9, 1.0, 0.9, 1.0);
_lastTextColor = Color.White;
break;
case ThemeStyle.Pastel:
_lastMainStart = RandomHueColor(0, 360, 0.25, 0.35, 0.8, 0.95);
_lastMainEnd = RandomHueColor(0, 360, 0.2, 0.3, 0.85, 1.0);
_lastAccentsStart = RandomHueColor(0, 360, 0.3, 0.4, 0.75, 0.9);
_lastAccentsEnd = RandomHueColor(0, 360, 0.25, 0.35, 0.9, 1.0);
_lastTextColor = Color.FromArgb(255, 80, 80, 80);
break;
case ThemeStyle.DarkGlow:
_lastMainStart = RandomHueColor(0, 360, 0.8, 1.0, 0.08, 0.15);
_lastMainEnd = RandomHueColor(0, 360, 0.8, 1.0, 0.1, 0.2);
_lastAccentsStart = RandomHueColor(0, 360, 0.9, 1.0, 0.75, 0.9);
_lastAccentsEnd = RandomHueColor(0, 360, 0.9, 1.0, 0.85, 1.0);
_lastTextColor = Color.FromArgb(255, 230, 230, 230);
break;
case ThemeStyle.Oceanic:
_lastMainStart = RandomHueColor(180, 220, 0.6, 0.8, 0.35, 0.5);
_lastMainEnd = RandomHueColor(190, 230, 0.7, 0.9, 0.6, 0.8);
_lastAccentsStart = RandomHueColor(160, 200, 0.8, 1.0, 0.75, 0.9);
_lastAccentsEnd = RandomHueColor(140, 180, 0.5, 0.7, 0.55, 0.7);
_lastTextColor = Color.FromArgb(255, 220, 240, 255);
break;
case ThemeStyle.Sunset:
_lastMainStart = RandomHueColor(10, 40, 0.7, 0.9, 0.5, 0.7);
int choice = _rand.Next(2);
int sunsetHueEnd = choice == 0
? SafeRandomRange(_rand, 350, 360)
: SafeRandomRange(_rand, 0, 10);
_lastMainEnd = ColorFromHSV(sunsetHueEnd, _rand.NextDouble() * 0.2 + 0.6, _rand.NextDouble() * 0.3 + 0.4);
_lastAccentsStart = RandomHueColor(20, 60, 0.8, 1.0, 0.8, 1.0);
_lastAccentsEnd = RandomHueColor(0, 20, 0.7, 0.9, 0.6, 0.8);
_lastTextColor = Color.FromArgb(255, 255, 230, 220);
break;
case ThemeStyle.Cyberpunk:
_lastMainStart = RandomHueColor(240, 260, 0.7, 1.0, 0.03, 0.1);
_lastMainEnd = RandomHueColor(270, 290, 0.8, 1.0, 0.1, 0.3);
_lastAccentsStart = RandomHueColor(300, 340, 0.9, 1.0, 0.8, 1.0);
_lastAccentsEnd = RandomHueColor(180, 220, 0.9, 1.0, 0.8, 1.0);
_lastTextColor = Color.White;
break;
case ThemeStyle.Forest:
_lastMainStart = RandomHueColor(90, 140, 0.5, 0.7, 0.3, 0.5);
_lastMainEnd = RandomHueColor(80, 130, 0.6, 0.8, 0.5, 0.7);
_lastAccentsStart = RandomHueColor(60, 100, 0.7, 0.9, 0.6, 0.8);
_lastAccentsEnd = RandomHueColor(80, 120, 0.6, 0.8, 0.5, 0.7);
_lastTextColor = Color.FromArgb(255, 220, 230, 210);
break;
case ThemeStyle.Retro:
_lastMainStart = RandomHueColor(270, 320, 0.4, 0.6, 0.25, 0.45);
_lastMainEnd = RandomHueColor(10, 40, 0.4, 0.6, 0.35, 0.55);
_lastAccentsStart = RandomHueColor(20, 50, 0.5, 0.7, 0.5, 0.7);
_lastAccentsEnd = RandomHueColor(40, 70, 0.4, 0.6, 0.4, 0.6);
_lastTextColor = RandomHueColor(0, 40, 0.5, 0.7, 0.3, 0.5);
break;
case ThemeStyle.Metallic:
_lastMainStart = RandomHueColor(200, 240, 0.05, 0.15, 0.3, 0.5);
_lastMainEnd = RandomHueColor(30, 50, 0.1, 0.2, 0.55, 0.75);
_lastAccentsStart = RandomHueColor(0, 60, 0.3, 0.5, 0.65, 0.85);
_lastAccentsEnd = RandomHueColor(180, 220, 0.2, 0.4, 0.5, 0.7);
_lastTextColor = Color.FromArgb(255, 245, 245, 245);
break;
case ThemeStyle.Candy:
_lastMainStart = RandomHueColor(300, 340, 0.7, 0.9, 0.8, 1.0);
_lastMainEnd = RandomHueColor(330, 360, 0.8, 1.0, 0.7, 0.9);
_lastAccentsStart = RandomHueColor(340, 360, 0.9, 1.0, 0.8, 1.0);
_lastAccentsEnd = RandomHueColor(310, 350, 0.8, 0.9, 0.75, 0.85);
_lastTextColor = Color.FromArgb(255, 50, 40, 70);
break;
case ThemeStyle.Space:
_lastMainStart = RandomHueColor(220, 260, 0.7, 0.9, 0.03, 0.1);
_lastMainEnd = RandomHueColor(220, 260, 0.6, 0.8, 0.2, 0.4);
_lastAccentsStart = RandomHueColor(240, 280, 0.7, 0.9, 0.7, 0.9);
_lastAccentsEnd = RandomHueColor(210, 250, 0.6, 0.8, 0.6, 0.8);
_lastTextColor = Color.WhiteSmoke;
break;
case ThemeStyle.Vintage:
_lastMainStart = RandomHueColor(30, 50, 0.4, 0.6, 0.4, 0.6);
_lastMainEnd = RandomHueColor(20, 40, 0.3, 0.5, 0.4, 0.6);
_lastAccentsStart = RandomHueColor(30, 60, 0.5, 0.7, 0.5, 0.7);
_lastAccentsEnd = RandomHueColor(10, 30, 0.4, 0.6, 0.4, 0.6);
_lastTextColor = RandomHueColor(10, 40, 0.4, 0.6, 0.25, 0.4);
break;
case ThemeStyle.Aurora:
_lastMainStart = RandomHueColor(150, 190, 0.7, 0.9, 0.3, 0.5);
_lastMainEnd = RandomHueColor(280, 320, 0.7, 0.9, 0.4, 0.6);
_lastAccentsStart = RandomHueColor(100, 140, 0.9, 1.0, 0.6, 0.8);
_lastAccentsEnd = RandomHueColor(220, 260, 0.8, 1.0, 0.7, 0.85);
_lastTextColor = Color.FromArgb(255, 230, 250, 240);
break;
case ThemeStyle.DarkRandom:
// Generate completely random unique dark theme colors (darker, low V in HSV)
// Generate colors with value typically between 0.1 and 0.35 (dark), saturation moderate to high 0.5 to 1
// Ensure uniqueness within generated colors
// Generator function for a random dark color
Func<Color> genDarkColor = () =>
{
double hue = _rand.NextDouble() * 360;
double saturation = _rand.NextDouble() * 0.5 + 0.5; // 0.5 - 1.0 sat
double value = _rand.NextDouble() * 0.25 + 0.1; // 0.1 - 0.35 val
return ColorFromHSV(hue, saturation, value);
};
var uniqueColors = GenerateUniqueColors(5, genDarkColor);
_lastMainStart = uniqueColors[0];
_lastMainEnd = uniqueColors[1];
_lastAccentsStart = uniqueColors[2];
_lastAccentsEnd = uniqueColors[3];
// For text color, pick a color contrasting with mainEnd, typically light and readable but unique
// We pick a color in high value range but avoid duplicates
Color genTextColor()
{
for (int i = 0; i < 100; i++)
{
double hue = _rand.NextDouble() * 360;
double saturation = _rand.NextDouble() * 0.3 + 0.2; // low saturation so readable
double value = _rand.NextDouble() * 0.4 + 0.6; // bright text, 0.6-1.0
Color c = ColorFromHSV(hue, saturation, value);
int key = (c.R << 16) | (c.G << 8) | c.B;
if (!uniqueColors.Exists(x => x.R == c.R && x.G == c.G && x.B == c.B))
return c;
}
return Color.White;
}
_lastTextColor = genTextColor();
break;
}
}
Theme(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor);
}
private void Theme(Color mainStart, Color mainEnd, Color accentsStart, Color accentsEnd, Color textcolor)
{
void SetGradient(Control control, Color startColor, Color endColor)
{
if (control == null || control.Width == 0 || control.Height == 0)
return;
Bitmap bmp = new Bitmap(control.Width, control.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
new Rectangle(0, 0, bmp.Width, bmp.Height),
startColor,
endColor,
System.Drawing.Drawing2D.LinearGradientMode.Vertical))
{
g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height);
}
}
control.BackgroundImage = bmp;
control.BackgroundImageLayout = ImageLayout.Stretch;
}
Color GetContrastingTextColor(Color background, Color fallback)
{
double luminance = (0.2126 * background.R + 0.7152 * background.G + 0.0722 * background.B) / 255;
if (luminance > 0.7)
return Color.FromArgb(255, 30, 30, 30);
else if (luminance < 0.15)
return Color.White;
else
return fallback;
}
// Clear all backgrounds and images first
var allPanels = new Panel[]
{
panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, panel10, indexpnl
};
foreach (var pnl in allPanels)
{
if (pnl != null)
{
pnl.BackgroundImage = null;
pnl.BackColor = Color.Transparent;
}
}
var labels = new Label[]
{
label1, label2, label3, label4, label5, label6, label7, label8,
label9, label10, label11, label12, label13, label14, label15,
label16, label17, label18, label19, label20, label21, label22,
label23, label24, label25, label26, label27, label28, label29,
label30, label31, label32, label33, label34, label35, label36,
label41, MyLink
};
foreach (var lbl in labels)
{
if (lbl != null)
{
lbl.BackgroundImage = null;
lbl.BackColor = Color.Transparent;
}
}
var pictures = new PictureBox[]
{
pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5,
pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, OffMap
};
foreach (var pb in pictures)
{
if (pb != null)
{
pb.Image = null;
pb.BackgroundImage = null;
pb.BackColor = Color.Transparent;
}
}
if (menuStrip1 != null)
{
menuStrip1.BackgroundImage = null;
menuStrip1.BackColor = Color.Transparent;
}
var menuItems = new ToolStripMenuItem[]
{
fileToolStripMenuItem, serverToolStripMenuItem, fishSpeechToolStripMenuItem, sTARTToolStripMenuItem,
whisperTurboToolStripMenuItem, sTARTToolStripMenuItem1, editToolStripMenuItem, settingsToolStripMenuItem,
formSettingsToolStripMenuItem, topmostToolStripMenuItem, yESToolStripMenuItem, nOToolStripMenuItem,
commSettingsToolStripMenuItem, chatComboToolStripMenuItem, oNToolStripMenuItem, oFFToolStripMenuItem,
partyModeToolStripMenuItem, oNToolStripMenuItem1, oFFToolStripMenuItem1, helpToolStripMenuItem,
pushToTalkToolStripMenuItem, enableToolStripMenuItem, disableToolStripMenuItem, aboutToolStripMenuItem,
toolsToolStripMenuItem, importToolStripMenuItem, voiceToolStripMenuItem, matchRecordToolStripMenuItem,
voiceToolStripMenuItem1, recordToolStripMenuItem, stopRecordToolStripMenuItem, keypadderToolStripMenuItem,
confirmModeToolStripMenuItem, tTSBaseToolStripMenuItem, fishSpeechToolStripMenuItem1, zonosToolStripMenuItem,
viewToolStripMenuItem, tTSToolStripMenuItem, fishSpeechToolStripMenuItem2, zonosToolStripMenuItem1,
constructiveChunksToolStripMenuItem, constructiveTokensToolStripMenuItem, ollamaToolStripMenuItem,
longGenerationsModeToolStripMenuItem, translationModeToolStripMenuItem, spellCheckModeToolStripMenuItem,
debugToolStripMenuItem, sTTToolStripMenuItem, oNToolStripMenuItem2, oFFToolStripMenuItem2,
portableChatboxToolStripMenuItem, oNToolStripMenuItem3, oFFToolStripMenuItem3, indexTTSToolStripMenuItem,
sTARTToolStripMenuItem2, recentPlayersToolStripMenuItem, incrementalSeedingToolStripMenuItem,
stateToolStripMenuItem, oFFToolStripMenuItem4, previewModeToolStripMenuItem, oNToolStripMenuItem4,
oFFToolStripMenuItem5, finetuneModelToolStripMenuItem, fishSpeechToolStripMenuItem3, toolStripMenuItem3,
makeToolStripMenuItem, startTrainToolStripMenuItem, outputsToolStripMenuItem, cacheOutputsToolStripMenuItem,
setDirectorytToolStripMenuItem,extrasToolStripMenuItem, themeToolStripMenuItem, rollDiceToolStripMenuItem, customizeToolStripMenuItem,
};
foreach (var item in menuItems)
{
if (item != null)
{
item.BackgroundImage = null;
item.BackColor = Color.Transparent;
}
}
if (statusStrip1 != null)
{
statusStrip1.BackgroundImage = null;
statusStrip1.BackColor = Color.Transparent;
}
if (toolStripStatusLabel1 != null)
toolStripStatusLabel1.BackgroundImage = null;
if (toolStripStatusLabel2 != null)
toolStripStatusLabel2.BackgroundImage = null;
if (toolStripProgressBar1 != null)
toolStripProgressBar1.BackgroundImage = null;
if (VoicesList != null)
{
VoicesList.BackgroundImage = null;
}
var textBoxes = new TextBox[]
{
textBox1, textBox2, textBox3, RepBox, TopPBox, MaxTokenBox, ChunkBox, TempBox,
HappyBox, AngryBox, ShockedBox, ScaredBox, GrossBox, SadBox, NeutralBox,
OtherBox, SpeechSpeedBox, CFGBox, SearchBox
};
foreach (var tb in textBoxes)
{
if (tb != null)
{
tb.BackgroundImage = null;
tb.BackColor = Color.White;
}
}
var combos = new ComboBox[]
{
Previews, comboBox1, comboBox2, comboBox4, comboBoxModels, TranslationMdl, SpellCheckMdl, comboBoxOutputDevices, comboBoxInputDevices
};
foreach (var cb in combos)
{
if (cb != null)
{
cb.BackgroundImage = null;
cb.BackColor = Color.White;
}
}
var buttons = new Button[]
{
F3B, button2, button4, button3, ListenButton, button7, button6,
Key_1_NUM, F2B, Key_16_ZERO, Key_15, Key_8_PLUS, Key_14_THREE,
Key_13_TWO, Key_12_ONE, Key_11_SIX, Key_FIVE, Key_9_FOUR,
Key_7_NINE, Key_6_EIGHT, Key_5_SEVEN, Key_4_MIN, Key_3_MULTI,
Key_2_SLASH, button5, F3BB, F8B, F7B, F6B, F5B, F4B, F12B,
F11B, F10B, F9B, F1B, button1, button13, button12, button8,
button10, button11, HP, SP, SN, HN, SHN, SHP, GN, GP, NN,
NP, AN, AP, SCN, SCP, ON, OP, button9, CFGN, CFGP, SPSN,
SPSP, button16, button17, SpeakerAP, Bum, button14, LookButton
};
foreach (var btn in buttons)
{
if (btn != null)
{
btn.BackgroundImage = null;
btn.Image = null;
btn.FlatAppearance.BorderColor = Color.Empty;
btn.FlatAppearance.BorderSize = 0;
btn.BackColor = Color.Transparent;
}
}
var checkBoxes = new CheckBox[]
{
EnabPrefix, AutoEmote, checkBox3
};
foreach (var cb in checkBoxes)
{
if (cb != null)
{
cb.BackgroundImage = null;
cb.BackColor = Color.Transparent;
}
}
// Re-apply colors and gradients
foreach (var lbl in labels)
{
if (lbl != null)
{
lbl.ForeColor = textcolor;
}
}
foreach (var pnl in allPanels)
{
if (pnl != null)
{
SetGradient(pnl, mainStart, mainEnd);
}
}
foreach (var pb in pictures)
{
if (pb != null)
{
pb.BackColor = Color.Transparent;
}
}
if (menuStrip1 != null)
{
menuStrip1.BackColor = accentsStart;
menuStrip1.ForeColor = GetContrastingTextColor(accentsStart, textcolor);
}
foreach (var item in menuItems)
{
if (item != null)
{
item.BackColor = accentsStart;
item.ForeColor = GetContrastingTextColor(accentsStart, textcolor);
}
}
if (statusStrip1 != null)
{
statusStrip1.BackColor = accentsEnd;
statusStrip1.ForeColor = GetContrastingTextColor(accentsEnd, textcolor);
}
if (toolStripStatusLabel1 != null)
toolStripStatusLabel1.ForeColor = textcolor;
if (toolStripStatusLabel2 != null)
toolStripStatusLabel2.ForeColor = textcolor;
if (toolStripProgressBar1 != null)
{
toolStripProgressBar1.BackColor = accentsStart;
toolStripProgressBar1.ForeColor = textcolor;
}
if (VoicesList != null)
{
VoicesList.BackColor = mainStart;
VoicesList.ForeColor = GetContrastingTextColor(mainStart, textcolor);
}
foreach (var tb in textBoxes)
{
if (tb != null)
{
tb.BackColor = mainEnd;
tb.ForeColor = GetContrastingTextColor(mainEnd, textcolor);
tb.BorderStyle = BorderStyle.FixedSingle;
}
}
foreach (var cb in combos)
{
if (cb != null)
{
cb.BackColor = mainEnd;
cb.ForeColor = GetContrastingTextColor(mainEnd, textcolor);
}
}
foreach (var btn in buttons)
{
if (btn == null) continue;
var btnStart = ShiftColorRandomly(accentsStart, 10);
var btnEnd = ShiftColorRandomly(accentsEnd, 20);
SetGradient(btn, btnStart, btnEnd);
Color midColor = Color.FromArgb(
(btnStart.R + btnEnd.R) / 2,
(btnStart.G + btnEnd.G) / 2,
(btnStart.B + btnEnd.B) / 2);
btn.ForeColor = GetContrastingTextColor(midColor, textcolor);
btn.FlatAppearance.BorderColor = DarkenColor(midColor, 0.3f);
btn.FlatAppearance.BorderSize = 1;
btn.FlatStyle = FlatStyle.Flat;
}
foreach (var cb in checkBoxes)
{
if (cb != null)
{
cb.ForeColor = textcolor;
cb.BackColor = Color.Transparent;
}
}
Bitmap formBmp = new Bitmap(this.Width, this.Height);
using (Graphics g = Graphics.FromImage(formBmp))
{
var angleOptions = new[]
{
System.Drawing.Drawing2D.LinearGradientMode.Vertical,
System.Drawing.Drawing2D.LinearGradientMode.Horizontal,
System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal,
System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal
};
var angle = angleOptions[_rand.Next(angleOptions.Length)];
Color start = ShiftColorRandomly(mainStart, 15);
Color end = ShiftColorRandomly(accentsStart, 25);
using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
new Rectangle(0, 0, formBmp.Width, formBmp.Height),
start,
end,
angle))
{
g.FillRectangle(brush, 0, 0, formBmp.Width, formBmp.Height);
}
}
this.BackgroundImage = formBmp;
this.BackgroundImageLayout = ImageLayout.Stretch;
}
private Color ShiftColorRandomly(Color baseColor, int maxShift)
{
int ShiftChannel(int channel) => Clamp(channel + _rand.Next(-maxShift, maxShift + 1), 0, 255);
return Color.FromArgb(baseColor.A, ShiftChannel(baseColor.R), ShiftChannel(baseColor.G), ShiftChannel(baseColor.B));
}