Last active
June 17, 2022 20:42
-
-
Save swharden/5b50b9a09dfab386ae5297a61779cca2 to your computer and use it in GitHub Desktop.
A C# .NET 6 app for generating XML color palettes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This .NET 6 console app generates XML color palette files compatible with Adobe Illustrator and CorelDraw. | |
// Color palettes are sourced from the ScottPlot package. | |
foreach (var pal in ScottPlot.Palette.GetPalettes()) | |
{ | |
string xml = GetPaletteXml(pal); | |
string saveFolder = Path.GetFullPath("palettes"); | |
if (!Directory.Exists(saveFolder)) | |
Directory.CreateDirectory(saveFolder); | |
string saveFilePath = Path.Combine(saveFolder, pal.Name + ".xml"); | |
File.WriteAllText(saveFilePath, xml); | |
Console.WriteLine(saveFilePath); | |
} | |
static string GetPaletteXml(ScottPlot.Drawing.Palette pal) | |
{ | |
System.Text.StringBuilder sb = new(); | |
sb.AppendLine("<?xml version='1.0'?>"); | |
sb.AppendLine($"<palette guid='{Guid.NewGuid()}' name='{pal.Name}'>"); | |
sb.AppendLine(" <colors>"); | |
sb.AppendLine(" <page>"); | |
foreach (var color in pal.GetColors(pal.Count())) | |
{ | |
string tints = $"{color.R / 255.0},{color.G / 255.0},{color.B / 255.0}"; | |
sb.AppendLine($"<color cs='RGB' name='Red' tints='{tints}' />"); | |
} | |
sb.AppendLine(" </page>"); | |
sb.AppendLine(" </colors>"); | |
sb.AppendLine("</palette>"); | |
return sb.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment