Skip to content

Instantly share code, notes, and snippets.

@Jesus-QC
Created January 23, 2022 13:59
Show Gist options
  • Save Jesus-QC/fc909283acfc405fac9d2d529d5e99ec to your computer and use it in GitHub Desktop.
Save Jesus-QC/fc909283acfc405fac9d2d529d5e99ec to your computer and use it in GitHub Desktop.
@page "/tools/scpsl/servernamecreator"
@using MudBlazor.Utilities
@using Color = System.Drawing.Color
<PageTitle>Server Name Creator | Jesus QC</PageTitle>
<h3>Faded Server Name Creator</h3>
<div style="background-color: @FirstColor; padding: 11px; border-radius: 10px">
First Color
<MudColorPicker @bind-Value="FirstColor" />
</div>
<br/>
<div style="background-color: @SecondColor; padding: 11px; border-radius: 10px">
Second Color
<MudColorPicker @bind-Value="SecondColor" />
</div>
<br/>
<br/>
<MudTextField @bind-Value="Input" Label="Input" Variant="Variant.Outlined"></MudTextField>
<br/>
<br/>
<div style="text-align: center">
<MudButton Variant="Variant.Filled" Color="MudBlazor.Color.Info" OnClick="Create">Create!</MudButton>
</div>
<br/>
<MudTextField @bind-Value="Output" Label="Output" Variant="Variant.Outlined" Disabled="true"></MudTextField>
<br/>
<div style="text-align: center; font-size: 20px; background-color: #181414; padding: 11px; border-radius: 10px">
Preview:
<br/>
@((MarkupString)Html!)
</div>
@code {
public MudColor FirstColor { get; set; } = "#594AE2";
public MudColor OldColor { get; set; } = "#999";
public MudColor SecondColor { get; set; } = "#FF4081";
public MudColor OldSecondColor { get; set; } = "#999";
public string Input { get; set; } = "Here goes your server name.";
public string OldInput { get; set; } = "";
public string Output { get; set; } = "Waiting.";
public string? Html { get; set; }
public void Create()
{
if(Input == OldInput && FirstColor == OldColor && SecondColor == OldSecondColor)
return;
Html = CreateGradient(Input, FirstColor, SecondColor, out var output);
Output = output;
OldInput = Input;
OldColor = FirstColor;
OldSecondColor = SecondColor;
}
string CreateGradient(string txt, MudColor color, MudColor finalColor, out string output)
{
int rMax = finalColor.R;
int rMin = color.R;
int gMax = finalColor.G;
int gMin = color.G;
int bMax = finalColor.B;
int bMin = color.B;
var size = txt.Length;
var colorList = new List<Color>();
for(int i = 0; i < size; i++)
{
var rAverage = rMin + (rMax - rMin) * i / size;
var gAverage = gMin + (gMax - gMin) * i / size;
var bAverage = bMin + (bMax - bMin) * i / size;
colorList.Add(Color.FromArgb(rAverage, gAverage, bAverage));
}
var finalString = "";
var finalHtml = "";
for (int i = 0; i < size; i++)
{
if (txt[i] != ' ')
{
var colorr = HexConverter(colorList[i]);
finalString += $"<color={colorr}>{txt[i]}</color>";
finalHtml += $"<span style=\"color: {colorr}\">{txt[i]}</span>";
}
else
{
finalString += " ";
finalHtml += "<span> </span>";
}
}
output = finalString;
return finalHtml;
}
string HexConverter(Color c)
{
var rtn = String.Empty;
try
{
rtn = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
catch (Exception)
{
//doing nothing
}
return rtn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment