public SetUnitBackColor ( Point point, BufferColor color ) : void | ||
point | Point | The location of the unit. |
color | BufferColor | The background color to set the unit to. |
리턴 | void |
private static ConsoleBuffer createBuffer(Bitmap image) { ConsoleBuffer buffer = new ConsoleBuffer(image.Width, image.Height); for (int i = 0; i < image.Width; i++) for (int j = 0; j < image.Height; j++) { Color c = image.GetPixel(i, j); if (c.A == 0) continue; double[,] distances = new double[16, 2]; double smallestDistance = -1; int smallestKey = 0; for (var k = 0; k < 16; k++) { // euclidean distance between colors double distance = (double)Math.Sqrt(Math.Pow(c.R - Colors[k, 0], 2) + Math.Pow(c.G - Colors[k, 1], 2) + Math.Pow(c.B - Colors[k, 2], 2)); if (smallestDistance > distance || smallestDistance == -1) { smallestDistance = distance; smallestKey = k; } } buffer.SetUnitBackColor(i, j, (BufferColor)Enum.GetValues(typeof(BufferColor)).GetValue(smallestKey)); } return buffer; }
private static ConsoleBuffer createBuffer(Bitmap image) { ConsoleBuffer buffer = new ConsoleBuffer(image.Width, image.Height); for (int i = 0; i < image.Width; i++) { for (int j = 0; j < image.Height; j++) { Color c = image.GetPixel(i, j); if (c.A == 0) { continue; } double[,] distances = new double[16, 2]; double smallestDistance = -1; int smallestKey = 0; for (var k = 0; k < 16; k++) { // euclidean distance between colors double distance = (double)Math.Sqrt(Math.Pow(c.R - Colors[k, 0], 2) + Math.Pow(c.G - Colors[k, 1], 2) + Math.Pow(c.B - Colors[k, 2], 2)); if (smallestDistance > distance || smallestDistance == -1) { smallestDistance = distance; smallestKey = k; } } buffer.SetUnitBackColor(i, j, (BufferColor)Enum.GetValues(typeof(BufferColor)).GetValue(smallestKey)); } } return(buffer); }
/// <summary> /// Draws text to a buffer using the specified settings. /// </summary> /// <param name="buffer">The buffer to draw to.</param> /// <param name="text">The text to draw.</param> /// <param name="position">The position of the text.</param> /// <param name="brush">The brush to draw the text with.</param> /// <param name="alignment">The alignment of the text relative to its position.</param> public void Draw(ConsoleBuffer buffer, string text, Point position, BufferBrush brush, Alignment alignment) { int // Character offsets mx = 0, my = 0; Point p = new Point(); Point pc = new Point(); foreach (char c in text) { p.X = alignment == Alignment.Left ? mx : -CharWidth - mx; p.Y = my; p = p + position; if (c == '\n') { mx = 0; my += CharHeight + 1; } else if (!Char.IsControl(c)) { for (int i = 0; i < glyphs[c].Length; i++) { if (c > glyphs.Length) { continue; } if (glyphs[c] == null) { continue; } pc.Y = i; for (int j = 0; j < glyphs[c][i].Length; j++) { if (glyphs[c][i] == null) { continue; } if (!glyphs[c][i][j]) { continue; } pc.X = j; buffer.SetUnitBackColor(p + pc, brush.GetColor(p.X + pc.X, p.Y + pc.Y)); } } mx += CharWidth + 1; } } }
/// <summary> /// Draws text to a buffer using the specified settings. /// </summary> /// <param name="buffer">The buffer to draw to.</param> /// <param name="text">The text to draw.</param> /// <param name="position">The position of the text.</param> /// <param name="brush">The brush to draw the text with.</param> /// <param name="alignment">The alignment of the text relative to its position.</param> public void Draw(ConsoleBuffer buffer, string text, Point position, BufferBrush brush, Alignment alignment) { int // Character offsets mx = 0, my = 0; Point p = new Point(); Point pc = new Point(); foreach(char c in text) { p.X = alignment == Alignment.Left ? mx : -CharWidth - mx; p.Y = my; p = p + position; if (c == '\n') { mx = 0; my += CharHeight + 1; } else if (!Char.IsControl(c)) { for (int i = 0; i < glyphs[c].Length; i++) { if (c > glyphs.Length) continue; if (glyphs[c] == null) continue; pc.Y = i; for(int j = 0; j < glyphs[c][i].Length; j++) { if (glyphs[c][i] == null) continue; if (!glyphs[c][i][j]) continue; pc.X = j; buffer.SetUnitBackColor(p + pc, brush.GetColor(p.X + pc.X, p.Y + pc.Y)); } } mx += CharWidth + 1; } } }