├── .gitignore
├── Avalonia.ColorGenerator.sln
├── Avalonia.ColorGenerator
├── Avalonia.ColorGenerator.csproj
├── Avalonia.ColorPack
│ ├── AvaloniaColorPack.cs
│ └── KnownColor.cs
├── Color
│ ├── ColorDefinition.cs
│ └── ColorWithValue.cs
├── ColorGenerator.cs
├── IColorPack.cs
└── LICENSE.txt
├── Example.png
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | **/.idea
8 | *.rsuser
9 | *.suo
10 | *.user
11 | *.userosscache
12 | *.sln.docstates
13 | [Bb]in/
14 | [Oo]bj/
15 | *.nupkg
16 |
17 | # User-specific files (MonoDevelop/Xamarin Studio)
18 | *.userprefs
19 |
20 | # Mono auto generated files
21 | mono_crash.*
22 |
23 | # Build results
24 | [Dd]ebug/
25 | [Dd]ebugPublic/
26 | [Rr]elease/
27 | [Rr]eleases/
28 | x64/
29 | x86/
30 | [Aa][Rr][Mm]/
31 | [Aa][Rr][Mm]64/
32 | bld/
33 | [Bb]in/
34 | [Oo]bj/
35 | [Ll]og/
36 | [Ll]ogs/
37 |
38 | # Visual Studio 2015/2017 cache/options directory
39 | .vs/
40 | # Uncomment if you have tasks that create the project's static files in wwwroot
41 | #wwwroot/
42 |
43 | # Visual Studio 2017 auto generated files
44 | Generated\ Files/
45 |
46 | # MSTest test Results
47 | [Tt]est[Rr]esult*/
48 | [Bb]uild[Ll]og.*
49 |
50 | # NUnit
51 | *.VisualState.xml
52 | TestResult.xml
53 | nunit-*.xml
54 |
55 | # Build Results of an ATL Project
56 | [Dd]ebugPS/
57 | [Rr]eleasePS/
58 | dlldata.c
59 |
60 | # Benchmark Results
61 | BenchmarkDotNet.Artifacts/
62 |
63 | # .NET Core
64 | project.lock.json
65 | project.fragment.lock.json
66 | artifacts/
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.vspscc
94 | *.vssscc
95 | .builds
96 | *.pidb
97 | *.svclog
98 | *.scc
99 |
100 | # Chutzpah Test files
101 | _Chutzpah*
102 |
103 | # Visual C++ cache files
104 | ipch/
105 | *.aps
106 | *.ncb
107 | *.opendb
108 | *.opensdf
109 | *.sdf
110 | *.cachefile
111 | *.VC.db
112 | *.VC.VC.opendb
113 |
114 | # Visual Studio profiler
115 | *.psess
116 | *.vsp
117 | *.vspx
118 | *.sap
119 |
120 | # Visual Studio Trace Files
121 | *.e2e
122 |
123 | # TFS 2012 Local Workspace
124 | $tf/
125 |
126 | # Guidance Automation Toolkit
127 | *.gpState
128 |
129 | # ReSharper is a .NET coding add-in
130 | _ReSharper*/
131 | *.[Rr]e[Ss]harper
132 | *.DotSettings.user
133 |
134 | # TeamCity is a build add-in
135 | _TeamCity*
136 |
137 | # DotCover is a Code Coverage Tool
138 | *.dotCover
139 |
140 | # AxoCover is a Code Coverage Tool
141 | .axoCover/*
142 | !.axoCover/settings.json
143 |
144 | # Visual Studio code coverage results
145 | *.coverage
146 | *.coveragexml
147 |
148 | # NCrunch
149 | _NCrunch_*
150 | .*crunch*.local.xml
151 | nCrunchTemp_*
152 |
153 | # MightyMoose
154 | *.mm.*
155 | AutoTest.Net/
156 |
157 | # Web workbench (sass)
158 | .sass-cache/
159 |
160 | # Installshield output folder
161 | [Ee]xpress/
162 |
163 | # DocProject is a documentation generator add-in
164 | DocProject/buildhelp/
165 | DocProject/Help/*.HxT
166 | DocProject/Help/*.HxC
167 | DocProject/Help/*.hhc
168 | DocProject/Help/*.hhk
169 | DocProject/Help/*.hhp
170 | DocProject/Help/Html2
171 | DocProject/Help/html
172 |
173 | # Click-Once directory
174 | publish/
175 |
176 | # Publish Web Output
177 | *.[Pp]ublish.xml
178 | *.azurePubxml
179 | # Note: Comment the next line if you want to checkin your web deploy settings,
180 | # but database connection strings (with potential passwords) will be unencrypted
181 | *.pubxml
182 | *.publishproj
183 |
184 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
185 | # checkin your Azure Web App publish settings, but sensitive information contained
186 | # in these scripts will be unencrypted
187 | PublishScripts/
188 |
189 | # NuGet Packages
190 | *.nupkg
191 | # NuGet Symbol Packages
192 | *.snupkg
193 | # The packages folder can be ignored because of Package Restore
194 | **/[Pp]ackages/*
195 | # except build/, which is used as an MSBuild target.
196 | !**/[Pp]ackages/build/
197 | # Uncomment if necessary however generally it will be regenerated when needed
198 | #!**/[Pp]ackages/repositories.config
199 | # NuGet v3's project.json files produces more ignorable files
200 | *.nuget.props
201 | *.nuget.targets
202 |
203 | # Microsoft Azure Build Output
204 | csx/
205 | *.build.csdef
206 |
207 | # Microsoft Azure Emulator
208 | ecf/
209 | rcf/
210 |
211 | # Windows Store app package directories and files
212 | AppPackages/
213 | BundleArtifacts/
214 | Package.StoreAssociation.xml
215 | _pkginfo.txt
216 | *.appx
217 | *.appxbundle
218 | *.appxupload
219 |
220 | # Visual Studio cache files
221 | # files ending in .cache can be ignored
222 | *.[Cc]ache
223 | # but keep track of directories ending in .cache
224 | !?*.[Cc]ache/
225 |
226 | # Others
227 | ClientBin/
228 | ~$*
229 | *~
230 | *.dbmdl
231 | *.dbproj.schemaview
232 | *.jfm
233 | *.pfx
234 | *.publishsettings
235 | orleans.codegen.cs
236 |
237 | # Including strong name files can present a security risk
238 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
239 | #*.snk
240 |
241 | # Since there are multiple workflows, uncomment next line to ignore bower_components
242 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
243 | #bower_components/
244 |
245 | # RIA/Silverlight projects
246 | Generated_Code/
247 |
248 | # Backup & report files from converting an old project file
249 | # to a newer Visual Studio version. Backup files are not needed,
250 | # because we have git ;-)
251 | _UpgradeReport_Files/
252 | Backup*/
253 | UpgradeLog*.XML
254 | UpgradeLog*.htm
255 | ServiceFabricBackup/
256 | *.rptproj.bak
257 |
258 | # SQL Server files
259 | *.mdf
260 | *.ldf
261 | *.ndf
262 |
263 | # Business Intelligence projects
264 | *.rdl.data
265 | *.bim.layout
266 | *.bim_*.settings
267 | *.rptproj.rsuser
268 | *- [Bb]ackup.rdl
269 | *- [Bb]ackup ([0-9]).rdl
270 | *- [Bb]ackup ([0-9][0-9]).rdl
271 |
272 | # Microsoft Fakes
273 | FakesAssemblies/
274 |
275 | # GhostDoc plugin setting file
276 | *.GhostDoc.xml
277 |
278 | # Node.js Tools for Visual Studio
279 | .ntvs_analysis.dat
280 | node_modules/
281 |
282 | # Visual Studio 6 build log
283 | *.plg
284 |
285 | # Visual Studio 6 workspace options file
286 | *.opt
287 |
288 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
289 | *.vbw
290 |
291 | # Visual Studio LightSwitch build output
292 | **/*.HTMLClient/GeneratedArtifacts
293 | **/*.DesktopClient/GeneratedArtifacts
294 | **/*.DesktopClient/ModelManifest.xml
295 | **/*.Server/GeneratedArtifacts
296 | **/*.Server/ModelManifest.xml
297 | _Pvt_Extensions
298 |
299 | # Paket dependency manager
300 | .paket/paket.exe
301 | paket-files/
302 |
303 | # FAKE - F# Make
304 | .fake/
305 |
306 | # CodeRush personal settings
307 | .cr/personal
308 |
309 | # Python Tools for Visual Studio (PTVS)
310 | __pycache__/
311 | *.pyc
312 |
313 | # Cake - Uncomment if you are using it
314 | # tools/**
315 | # !tools/packages.config
316 |
317 | # Tabs Studio
318 | *.tss
319 |
320 | # Telerik's JustMock configuration file
321 | *.jmconfig
322 |
323 | # BizTalk build output
324 | *.btp.cs
325 | *.btm.cs
326 | *.odx.cs
327 | *.xsd.cs
328 |
329 | # OpenCover UI analysis results
330 | OpenCover/
331 |
332 | # Azure Stream Analytics local run output
333 | ASALocalRun/
334 |
335 | # MSBuild Binary and Structured Log
336 | *.binlog
337 |
338 | # NVidia Nsight GPU debugger configuration file
339 | *.nvuser
340 |
341 | # MFractors (Xamarin productivity tool) working folder
342 | .mfractor/
343 |
344 | # Local History for Visual Studio
345 | .localhistory/
346 |
347 | # BeatPulse healthcheck temp database
348 | healthchecksdb
349 |
350 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
351 | MigrationBackup/
352 |
353 | # Ionide (cross platform F# VS Code tools) working folder
354 | .ionide/
355 |
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.ColorGenerator", "Avalonia.ColorGenerator\Avalonia.ColorGenerator.csproj", "{ED02DEAB-76CD-46AC-A17A-83897B8C908B}"
4 | EndProject
5 | Global
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
7 | Debug|Any CPU = Debug|Any CPU
8 | Release|Any CPU = Release|Any CPU
9 | EndGlobalSection
10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
11 | {ED02DEAB-76CD-46AC-A17A-83897B8C908B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12 | {ED02DEAB-76CD-46AC-A17A-83897B8C908B}.Debug|Any CPU.Build.0 = Debug|Any CPU
13 | {ED02DEAB-76CD-46AC-A17A-83897B8C908B}.Release|Any CPU.ActiveCfg = Release|Any CPU
14 | {ED02DEAB-76CD-46AC-A17A-83897B8C908B}.Release|Any CPU.Build.0 = Release|Any CPU
15 | EndGlobalSection
16 | EndGlobal
17 |
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/Avalonia.ColorGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | LICENSE.txt
6 | AvaloniaColorGenerator
7 | GMIKE
8 | Generates a number for choosing a color from a ready set.
9 | https://github.com/RomanSoloweow/Avalonia.ColorGenerator
10 | https://github.com/RomanSoloweow/Avalonia.ColorGenerator
11 | Avallonia ColorGenerator
12 | true
13 | AvaloniaColorGenerator
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/Avalonia.ColorPack/AvaloniaColorPack.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Avalonia.ColorGenerator;
3 |
4 | namespace Avalonia.ColorPack
5 | {
6 | public class AvaloniaColorPack:IColorsPack
7 | {
8 | private static readonly Dictionary Colors = new()
9 | {
10 | {KnownColor.Black, "#000000"},
11 | {KnownColor.Navy, "#000080"},
12 | {KnownColor.DarkBlue, "#00008B"},
13 | {KnownColor.MediumBlue, "#0000CD"},
14 | {KnownColor.Blue, "#0000FF"},
15 | {KnownColor.DarkGreen, "#006400"},
16 | {KnownColor.Green, "#008000"},
17 | {KnownColor.Teal, "#008080"},
18 | {KnownColor.DarkCyan, "#008B8B"},
19 | {KnownColor.DeepSkyBlue, "#00BFFF"},
20 | {KnownColor.DarkTurquoise, "#00CED1"},
21 | {KnownColor.MediumSpringGreen, "#00FA9A"},
22 | {KnownColor.Lime, "#00FF00"},
23 | {KnownColor.SpringGreen, "#00FF7F"},
24 | {KnownColor.Aqua, "#00FFFF"},
25 | {KnownColor.Cyan, "#00FFFF"},
26 | {KnownColor.MidnightBlue, "#191970"},
27 | {KnownColor.DodgerBlue, "#1E90FF"},
28 | {KnownColor.LightSeaGreen, "#20B2AA"},
29 | {KnownColor.ForestGreen, "#228B22"},
30 | {KnownColor.SeaGreen, "#2E8B57"},
31 | {KnownColor.DarkSlateGray, "#2F4F4F"},
32 | {KnownColor.LimeGreen, "#32CD32"},
33 | {KnownColor.MediumSeaGreen, "#3CB371"},
34 | {KnownColor.Turquoise, "#40E0D0"},
35 | {KnownColor.RoyalBlue, "#4169E1"},
36 | {KnownColor.SteelBlue, "#4682B4"},
37 | {KnownColor.DarkSlateBlue, "#483D8B"},
38 | {KnownColor.MediumTurquoise, "#48D1CC"},
39 | {KnownColor.Indigo, "#4B0082"},
40 | {KnownColor.DarkOliveGreen, "#556B2F"},
41 | {KnownColor.CadetBlue, "#5F9EA0"},
42 | {KnownColor.CornflowerBlue, "#6495ED"},
43 | {KnownColor.MediumAquamarine, "#66CDAA"},
44 | {KnownColor.DimGray, "#696969"},
45 | {KnownColor.SlateBlue, "#6A5ACD"},
46 | {KnownColor.OliveDrab, "#6B8E23"},
47 | {KnownColor.SlateGray, "#708090"},
48 | {KnownColor.LightSlateGray, "#778899"},
49 | {KnownColor.MediumSlateBlue, "#7B68EE"},
50 | {KnownColor.LawnGreen, "#7CFC00"},
51 | {KnownColor.Chartreuse, "#7FFF00"},
52 | {KnownColor.Aquamarine, "#7FFFD4"},
53 | {KnownColor.Maroon, "#800000"},
54 | {KnownColor.Purple, "#800080"},
55 | {KnownColor.Olive, "#808000"},
56 | {KnownColor.Gray, "#808080"},
57 | {KnownColor.SkyBlue, "#87CEEB"},
58 | {KnownColor.LightSkyBlue, "#87CEFA"},
59 | {KnownColor.BlueViolet, "#8A2BE2"},
60 | {KnownColor.DarkRed, "#8B0000"},
61 | {KnownColor.DarkMagenta, "#8B008B"},
62 | {KnownColor.SaddleBrown, "#8B4513"},
63 | {KnownColor.DarkSeaGreen, "#8FBC8F"},
64 | {KnownColor.LightGreen, "#90EE90"},
65 | {KnownColor.MediumPurple, "#9370DB"},
66 | {KnownColor.DarkViolet, "#9400D3"},
67 | {KnownColor.PaleGreen, "#98FB98"},
68 | {KnownColor.DarkOrchid, "#9932CC"},
69 | {KnownColor.YellowGreen, "#9ACD32"},
70 | {KnownColor.Sienna, "#A0522D"},
71 | {KnownColor.Brown, "#A52A2A"},
72 | {KnownColor.DarkGray, "#A9A9A9"},
73 | {KnownColor.LightBlue, "#ADD8E6"},
74 | {KnownColor.GreenYellow, "#ADFF2F"},
75 | {KnownColor.PaleTurquoise, "#AFEEEE"},
76 | {KnownColor.LightSteelBlue, "#B0C4DE"},
77 | {KnownColor.PowderBlue, "#B0E0E6"},
78 | {KnownColor.Firebrick, "#B22222"},
79 | {KnownColor.DarkGoldenrod, "#B8860B"},
80 | {KnownColor.MediumOrchid, "#BA55D3"},
81 | {KnownColor.RosyBrown, "#BC8F8F"},
82 | {KnownColor.DarkKhaki, "#BDB76B"},
83 | {KnownColor.Silver, "#C0C0C0"},
84 | {KnownColor.MediumVioletRed, "#C71585"},
85 | {KnownColor.IndianRed, "#CD5C5C"},
86 | {KnownColor.Peru, "#CD853F"},
87 | {KnownColor.Chocolate, "#D2691E"},
88 | {KnownColor.Tan, "#D2B48C"},
89 | {KnownColor.LightGray, "#D3D3D3"},
90 | {KnownColor.Thistle, "#D8BFD8"},
91 | {KnownColor.Orchid, "#DA70D6"},
92 | {KnownColor.Goldenrod, "#DAA520"},
93 | {KnownColor.PaleVioletRed, "#DB7093"},
94 | {KnownColor.Crimson, "#DC143C"},
95 | {KnownColor.Gainsboro, "#DCDCDC"},
96 | {KnownColor.Plum, "#DDA0DD"},
97 | {KnownColor.BurlyWood, "#DEB887"},
98 | {KnownColor.LightCyan, "#E0FFFF"},
99 | {KnownColor.Lavender, "#E6E6FA"},
100 | {KnownColor.DarkSalmon, "#E9967A"},
101 | {KnownColor.Violet, "#EE82EE"},
102 | {KnownColor.PaleGoldenrod, "#EEE8AA"},
103 | {KnownColor.LightCoral, "#F08080"},
104 | {KnownColor.Khaki, "#F0E68C"},
105 | {KnownColor.AliceBlue, "#F0F8FF"},
106 | {KnownColor.Honeydew, "#F0FFF0"},
107 | {KnownColor.Azure, "#F0FFFF"},
108 | {KnownColor.SandyBrown, "#F4A460"},
109 | {KnownColor.Wheat, "#F5DEB3"},
110 | {KnownColor.Beige, "#F5F5DC"},
111 | {KnownColor.WhiteSmoke, "#F5F5F5"},
112 | {KnownColor.MintCream, "#F5FFFA"},
113 | {KnownColor.GhostWhite, "#F8F8FF"},
114 | {KnownColor.Salmon, "#FA8072"},
115 | {KnownColor.AntiqueWhite, "#FAEBD7"},
116 | {KnownColor.Linen, "#FAF0E6"},
117 | {KnownColor.LightGoldenrodYellow, "#FAFAD2"},
118 | {KnownColor.OldLace, "#FDF5E6"},
119 | {KnownColor.Red, "#FF0000"},
120 | {KnownColor.Fuchsia, "#FF00FF"},
121 | {KnownColor.Magenta, "#FF00FF"},
122 | {KnownColor.DeepPink, "#FF1493"},
123 | {KnownColor.OrangeRed, "#FF4500"},
124 | {KnownColor.Tomato, "#FF6347"},
125 | {KnownColor.HotPink, "#FF69B4"},
126 | {KnownColor.Coral, "#FF7F50"},
127 | {KnownColor.DarkOrange, "#FF8C00"},
128 | {KnownColor.LightSalmon, "#FFA07A"},
129 | {KnownColor.Orange, "#FFA500"},
130 | {KnownColor.LightPink, "#FFB6C1"},
131 | {KnownColor.Pink, "#FFC0CB"},
132 | {KnownColor.Gold, "#FFD700"},
133 | {KnownColor.PeachPuff, "#FFDAB9"},
134 | {KnownColor.NavajoWhite, "#FFDEAD"},
135 | {KnownColor.Moccasin, "#FFE4B5"},
136 | {KnownColor.Bisque, "#FFE4C4"},
137 | {KnownColor.MistyRose, "#FFE4E1"},
138 | {KnownColor.BlanchedAlmond, "#FFEBCD"},
139 | {KnownColor.PapayaWhip, "#FFEFD5"},
140 | {KnownColor.LavenderBlush, "#FFF0F5"},
141 | {KnownColor.SeaShell, "#FFF5EE"},
142 | {KnownColor.Cornsilk, "#FFF8DC"},
143 | {KnownColor.LemonChiffon, "#FFFACD"},
144 | {KnownColor.FloralWhite, "#FFFAF0"},
145 | {KnownColor.Snow, "#FFFAFA"},
146 | {KnownColor.Yellow, "#FFFF00"},
147 | {KnownColor.LightYellow, "#FFFFE0"},
148 | {KnownColor.Ivory, "#FFFFF0"},
149 | {KnownColor.White, "#FFFFFF"}
150 | };
151 |
152 | public int CountColors()
153 | {
154 | return Colors.Count;
155 | }
156 |
157 | public ColorDefinition GetColor(int index)
158 | {
159 | var colorEnum = (KnownColor)index;
160 | var hex = Colors[colorEnum];
161 |
162 | return new ColorDefinition(index, colorEnum.ToString(), hex);
163 | }
164 |
165 | public ColorDefinition GetColor(string colorName)
166 | {
167 | if (!KnownColor.TryParse(colorName, out KnownColor colorEnum)) return null;
168 | var hex = Colors[colorEnum];
169 |
170 | return new ColorDefinition((int)colorEnum, colorEnum.ToString(), hex);
171 |
172 | }
173 | }
174 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/Avalonia.ColorPack/KnownColor.cs:
--------------------------------------------------------------------------------
1 | namespace Avalonia.ColorPack
2 | {
3 | public enum KnownColor
4 | {
5 | Black = 0,
6 | Navy,
7 | DarkBlue,
8 | MediumBlue,
9 | Blue,
10 | DarkGreen,
11 | Green,
12 | Teal,
13 | DarkCyan,
14 | DeepSkyBlue,
15 | DarkTurquoise,
16 | MediumSpringGreen,
17 | Lime,
18 | SpringGreen,
19 | Aqua,
20 | Cyan,
21 | MidnightBlue,
22 | DodgerBlue,
23 | LightSeaGreen,
24 | ForestGreen,
25 | SeaGreen,
26 | DarkSlateGray,
27 | LimeGreen,
28 | MediumSeaGreen,
29 | Turquoise,
30 | RoyalBlue,
31 | SteelBlue,
32 | DarkSlateBlue,
33 | MediumTurquoise,
34 | Indigo,
35 | DarkOliveGreen,
36 | CadetBlue,
37 | CornflowerBlue,
38 | MediumAquamarine,
39 | DimGray,
40 | SlateBlue,
41 | OliveDrab,
42 | SlateGray,
43 | LightSlateGray,
44 | MediumSlateBlue,
45 | LawnGreen,
46 | Chartreuse,
47 | Aquamarine,
48 | Maroon,
49 | Purple,
50 | Olive,
51 | Gray,
52 | SkyBlue,
53 | LightSkyBlue,
54 | BlueViolet,
55 | DarkRed,
56 | DarkMagenta,
57 | SaddleBrown,
58 | DarkSeaGreen,
59 | LightGreen,
60 | MediumPurple,
61 | DarkViolet,
62 | PaleGreen,
63 | DarkOrchid,
64 | YellowGreen,
65 | Sienna,
66 | Brown,
67 | DarkGray,
68 | LightBlue,
69 | GreenYellow,
70 | PaleTurquoise,
71 | LightSteelBlue,
72 | PowderBlue,
73 | Firebrick,
74 | DarkGoldenrod,
75 | MediumOrchid,
76 | RosyBrown,
77 | DarkKhaki,
78 | Silver,
79 | MediumVioletRed,
80 | IndianRed,
81 | Peru,
82 | Chocolate,
83 | Tan,
84 | LightGray,
85 | Thistle,
86 | Orchid,
87 | Goldenrod,
88 | PaleVioletRed,
89 | Crimson,
90 | Gainsboro,
91 | Plum,
92 | BurlyWood,
93 | LightCyan,
94 | Lavender,
95 | DarkSalmon,
96 | Violet,
97 | PaleGoldenrod,
98 | LightCoral,
99 | Khaki,
100 | AliceBlue,
101 | Honeydew,
102 | Azure,
103 | SandyBrown,
104 | Wheat,
105 | Beige,
106 | WhiteSmoke,
107 | MintCream,
108 | GhostWhite,
109 | Salmon,
110 | AntiqueWhite,
111 | Linen,
112 | LightGoldenrodYellow,
113 | OldLace,
114 | Red,
115 | Fuchsia,
116 | Magenta,
117 | DeepPink,
118 | OrangeRed,
119 | Tomato,
120 | HotPink,
121 | Coral,
122 | DarkOrange,
123 | LightSalmon,
124 | Orange,
125 | LightPink,
126 | Pink,
127 | Gold,
128 | PeachPuff,
129 | NavajoWhite,
130 | Moccasin,
131 | Bisque,
132 | MistyRose,
133 | BlanchedAlmond,
134 | PapayaWhip,
135 | LavenderBlush,
136 | SeaShell,
137 | Cornsilk,
138 | LemonChiffon,
139 | FloralWhite,
140 | Snow,
141 | Yellow,
142 | LightYellow,
143 | Ivory,
144 | White
145 | }
146 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/Color/ColorDefinition.cs:
--------------------------------------------------------------------------------
1 | namespace Avalonia.ColorGenerator
2 | {
3 | public record ColorDefinition(int Index, string Name, string Hex);
4 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/Color/ColorWithValue.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Media;
2 |
3 | namespace Avalonia.ColorGenerator
4 | {
5 | public class ColorWithValue
6 | {
7 | public Color Color { get; set; }
8 | public int Index { get; set; }
9 | public string Name { get; set; }
10 | public string Hex { get; set; }
11 | public ColorWithValue(ColorDefinition color)
12 | {
13 | Color = Color.Parse(color.Hex);
14 | Index = color.Index;
15 | Name = color.Name;
16 | Hex = color.Hex;
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/ColorGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Avalonia.ColorPack;
5 |
6 | namespace Avalonia.ColorGenerator
7 | {
8 | public class ColorGenerator
9 | {
10 | private Random Random { get; } = new();
11 | public int CountColors { get; }
12 | private IColorsPack ColorsPack { get; }
13 | ///
14 | /// Shuffled list of color indices
15 | ///
16 | private List UniqueIndexes { get; } = new();
17 | ///
18 | /// Current unique color index
19 | ///
20 | private int CurrentUniqueIndexNumber { get; set; }
21 |
22 | ///
23 | /// Сache of colors
24 | ///
25 | private Dictionary ColorsWithValues{ get; } = new();
26 | ///
27 | /// Сache for indexes
28 | ///
29 | private Dictionary ColorsIndexByName { get; } = new();
30 |
31 | ///
32 | /// Reform unique on overflow
33 | ///
34 | public bool ReformUnique{ get; }
35 |
36 | ///
37 | /// Color Generator
38 | ///
39 | /// Pack of colors
40 | /// Overflow unique value flag:
41 | /// True - The list will be reformed.
42 | /// False - The list will start over.
43 | ///
44 | public ColorGenerator(IColorsPack pack = null, bool reformUnique = false)
45 | {
46 | ColorsPack = pack ?? new AvaloniaColorPack();
47 | ReformUnique = reformUnique;
48 | CountColors = ColorsPack.CountColors();
49 | FillUniqueValues();
50 | }
51 |
52 | public ColorWithValue Next()
53 | {
54 | var colorIndex = Random.Next(0, CountColors);
55 |
56 | if (!ColorsWithValues.ContainsKey(colorIndex))
57 | {
58 | var colorWithHex = ColorsPack.GetColor(colorIndex);
59 | AddColor(colorWithHex);
60 | }
61 |
62 | return ColorsWithValues[colorIndex];
63 | }
64 |
65 | public ColorWithValue NextUnique()
66 | {
67 | if (CurrentUniqueIndexNumber == CountColors)
68 | {
69 | if (ReformUnique)
70 | FillUniqueValues();
71 | CurrentUniqueIndexNumber = 0;
72 | }
73 |
74 |
75 | int colorIndex = UniqueIndexes[CurrentUniqueIndexNumber];
76 |
77 | CurrentUniqueIndexNumber++;
78 |
79 | if (!ColorsWithValues.ContainsKey(colorIndex))
80 | {
81 | var colorWithHex = ColorsPack.GetColor(colorIndex);
82 | AddColor(colorWithHex);
83 | }
84 |
85 | return ColorsWithValues[colorIndex];
86 | }
87 |
88 |
89 | public ColorWithValue GetColor(string colorName)
90 | {
91 | if (!ColorsIndexByName.ContainsKey(colorName))
92 | {
93 | var colorWithHex = ColorsPack.GetColor(colorName);
94 | AddColor(colorWithHex);
95 | }
96 |
97 | var colorIndex = ColorsIndexByName[colorName];
98 | return ColorsWithValues[colorIndex];
99 | }
100 |
101 | public ColorWithValue GetColor(int colorIndex)
102 | {
103 | if (!ColorsWithValues.ContainsKey(colorIndex))
104 | {
105 | var colorWithHex = ColorsPack.GetColor(colorIndex);
106 | AddColor(colorWithHex);
107 | }
108 |
109 | return ColorsWithValues[colorIndex];
110 | }
111 |
112 | private void AddColor(ColorDefinition color)
113 | {
114 | ColorsWithValues[color.Index] = new ColorWithValue(color);
115 | ColorsIndexByName[color.Name] = color.Index;
116 | }
117 |
118 |
119 | //based on answer https://codereview.stackexchange.com/questions/61338/generate-random-numbers-without-repetitions/61372#61372?newreg=1165f83d96ea41b7826d45b2a4621888
120 | private void FillUniqueValues()
121 | {
122 | HashSet candidates = new HashSet();
123 |
124 | // start Count values before Max, and end at Max
125 | for (int top = CountColors - CountColors; top < CountColors; top++)
126 | {
127 | // May strike a duplicate.
128 | // Need to add +1 to make inclusive generator
129 | // +1 is safe even for MaxVal Max value because top < Max
130 | if (!candidates.Add(Random.Next(0, top + 1))) {
131 | // collision, add inclusive Max.
132 | // which could not possibly have been added before.
133 | candidates.Add(top);
134 | }
135 | }
136 | List result = candidates.ToList();
137 |
138 | // shuffle the results because HashSet has messed
139 | // with the order, and the algorithm does not produce
140 | // random-ordered results (e.g. Max-1 will never be the first value)
141 | for (int i = result.Count - 1; i > 0; i--)
142 | {
143 | int k = Random.Next(i + 1);
144 | int tmp = result[k];
145 | result[k] = result[i];
146 | result[i] = tmp;
147 | }
148 |
149 | UniqueIndexes.AddRange(result);
150 | }
151 |
152 | }
153 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/IColorPack.cs:
--------------------------------------------------------------------------------
1 | namespace Avalonia.ColorGenerator
2 | {
3 | public interface IColorsPack
4 | {
5 | int CountColors();
6 | ColorDefinition GetColor(int colorNumber);
7 | ColorDefinition GetColor(string colorName);
8 | }
9 | }
--------------------------------------------------------------------------------
/Avalonia.ColorGenerator/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 GMIKE
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RomanSoloweow/Avalonia.ColorGenerator/a05d8e14b866706c34e470ffb3ff4f150718778d/Example.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 GMIKE
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.nuget.org/packages/AvaloniaColorGenerator) [](https://github.com/RomanSoloweow/Avalonia.ColorGenerator) [](https://github.com/RomanSoloweow/Avalonia.ColorGenerator) [](https://github.com/RomanSoloweow/Avalonia.ColorGenerator)
2 | [](https://github.com/RomanSoloweow/Avalonia.ColorGenerator)
3 |
4 | # Avalonia.ColorGenerator
5 |
6 | Generates a number for choosing a color from a ready set.
7 |
8 | Usage [example](https://github.com/RomanSoloweow/DraggableColors) (application with color display)
9 |
10 | 
11 |
12 | ```C#
13 | ColorGenerator generator = new();
14 | ```
15 | Get random color
16 | ```C#
17 | ColorWithValue value = generator.Next();
18 | ```
19 | Get random unique color (in case of overflow, the list will start over or be re-formed depending on the flag)
20 | ```C#
21 | ColorWithValue value = generator.NextUnique();
22 | ```
23 | You can implement your own set of colors for the generator by implementing the interface
24 | ```C#
25 | public interface IColorsPack
26 | {
27 | int CountColors();
28 | ColorDefinition GetColor(int colorNumber);
29 | ColorDefinition GetColor(string colorName);
30 | }
31 | ```
32 |
33 | Fields of color:
34 |
35 | - Color - Color for SolidColorBrush or other
36 | - Name - name of current color
37 | - Index - index of current color
38 | - Hex - Color Hex format
39 |
40 |
41 | ## License📑
42 |
43 | Licensed under the [MIT](LICENSE) license.
44 |
--------------------------------------------------------------------------------