asciipumper- mspaint style program to create irc ascii art |
git clone git://git.acid.vegas/asciipumper.git |
Log | Files | Refs | Archive | README |
ColorPalette.cs (3244B)
1 #region Copyright (c) 2007, PP4L Software 2 /************************************************************************************ 3 4 Copyright 2007, PP4L Software 5 Author: Lampiasis <lampiasis@dvolker.com> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 21 '***********************************************************************************/ 22 #endregion 23 24 using System; 25 using System.Collections.Generic; 26 using System.Text; 27 using System.Drawing; 28 29 namespace AsciiPumper 30 { 31 public class ColorPalette : List<Color> 32 { 33 34 public SolidBrush [] SolidBrushes = new SolidBrush[16]; 35 36 /* 37 0 white 38 1 black 39 2 blue (navy) 40 3 green 41 4 red 42 5 brown (maroon) 43 6 purple 44 7 orange (olive) 45 8 yellow 46 9 lt.green (lime) 47 10 teal (a kinda green/blue cyan) 48 11 lt.cyan (cyan ?) (aqua) 49 12 lt.blue (royal) 50 13 pink (light purple) (fuchsia) 51 14 grey 52 15 lt.grey (silver) 53 */ 54 public ColorPalette() : base(16) 55 { 56 57 58 this.Add(Color.White); 59 this.Add(Color.Black); 60 this.Add(Color.FromArgb(0, 0, 127)); // this.Add(Color.Blue); 61 this.Add(Color.FromArgb(0, 147, 0)); // this.Add(Color.Green); 62 this.Add(Color.FromArgb(255, 0, 0)); // this.Add(Color.Red); 63 this.Add(Color.FromArgb(127, 0, 0)); // this.Add(Color.Brown); 64 this.Add(Color.FromArgb(156, 0, 156)); // this.Add(Color.Purple); 65 this.Add(Color.FromArgb(252, 127, 0)); // this.Add(Color.Orange); 66 this.Add(Color.FromArgb(255, 255, 0)); // this.Add( Color.Yellow); 67 this.Add(Color.FromArgb(0, 252, 0)); // this.Add( Color.LightGreen); 68 this.Add(Color.FromArgb(0, 147, 147)); // this.Add( Color.Teal); 69 this.Add(Color.FromArgb(0, 255, 255)); // this.Add( Color.LightCyan); 70 this.Add(Color.FromArgb(0, 0, 252)); // this.Add( Color.LightBlue); 71 this.Add(Color.FromArgb(255, 0, 255)); // this.Add( Color.Pink); 72 this.Add(Color.FromArgb(127, 127, 127)); // this.Add( Color.Gray); 73 this.Add(Color.FromArgb(210, 210, 210)); // this.Add(Color.LightGray); 74 75 for(int i = 0; i < 16; i++) 76 SolidBrushes[i] = new SolidBrush(this[i]); 77 } 78 79 public byte FindClosestColor(Color color) 80 { 81 byte smallestindex = 0; 82 int smallestdistance = int.MaxValue; 83 84 for (byte i = 0; i < this.Count; i++) 85 { 86 87 Color curcolor = this[i]; 88 int distance = (curcolor.R - color.R) * (curcolor.R - color.R) + (curcolor.G - color.G) * (curcolor.G - color.G) + (curcolor.B - color.B) * (curcolor.B - color.B); 89 if (distance < smallestdistance) 90 { 91 smallestdistance = distance; 92 smallestindex = i; 93 } 94 } 95 96 return smallestindex; 97 } 98 } 99 }