public Route(string s) { if (s.Length > 0) { rs = s; Random rndm = new Random(); //color = RandomColor(); color = RandomColorHSV(rndm.Next(), 0.5, 0.95); Console.WriteLine("RandomColor {0}", color.ToString()); //color = Color. string[] ns = s.Split(); nodes = new int[ns.Length]; //if (ns.Length < 2) { throw new Exception("Route must have at least 2 nodes length"); } for (int i = 0; i < ns.Length; i++) { nodes[i] = int.Parse(ns[i]); } } else { Console.WriteLine("Empty route"); throw new Exception("Empty route"); } }
private void PictureBox_MF_Raw_MouseMove(object sender, MouseEventArgs e) { if (threadRaw != null) { return; } TextBox_MF_X_Left.Text = e.Location.X.ToString(); TextBox_MF_Y_Left.Text = e.Location.Y.ToString(); int xOfs = e.Location.X; int yOfs = e.Location.Y; if (rawBitMaps.Count < 1) { return; } Point adjustedPoint = adjustLocationLeft(xOfs, yOfs); try { System.Drawing.Color color0 = ((Bitmap)PictureBox_MF_Raw.Image).GetPixel(adjustedPoint.X, adjustedPoint.Y); TextBox_Left_Color.Text = color0.ToString(); } catch (Exception ex) { TextBox_Left_Color.Text = ""; } }
static void Main(string[] args) { System.Drawing.Color c1 = System.Drawing.Color.FromName("Blue"); Console.Write("c1.ToString() = "); Console.WriteLine(c1.ToString()); object o1 = c1; System.Drawing.Color c3 = (System.Drawing.Color)o1; Console.Write("((System.Drawing.Color)(object)c1).ToString() = "); Console.WriteLine(c3.ToString()); int n = c1.ToArgb(); Console.Write("c1.ToArgb() = "); Console.WriteLine(n); uint n1 = (uint)n; Console.Write("(uint)c1.ToArgb() = "); Console.WriteLine(n1); Energy.Base.Color x = (Energy.Base.Color)(uint) c1.ToArgb(); var html = x.ToString(); Console.Write("(string)(Energy.Base.Color) = "); Console.WriteLine(html); Energy.Base.Color x1 = new Energy.Base.Color((uint)c1.ToArgb()); var html1 = x1.ToString(); Console.Write("new Energy.Base.Color((uint)c.ToArgb()) = "); Console.WriteLine(html1); Console.ReadLine(); }
public static System.Drawing.Color ObtenerTonalidadOscuraDeColor(System.Drawing.Color color) { String stCol = color.ToString().Replace("#", ""); String r = stCol.Substring(0, 2); String v = stCol.Substring(2, 2); String a = stCol.Substring(4, 2); double ir = color.R; //Convert.ToInt32(r, 16); double iv = color.G; //Convert.ToInt32(v, 16); double ia = color.B; //Convert.ToInt32(a, 16); double factor = 40; if (ir - factor >= 0) { ir -= factor; } if (iv - factor >= 0) { iv -= factor; } if (ia - factor >= 0) { ia -= factor; } System.Drawing.Color colorNuevo = System.Drawing.Color.FromArgb((byte)ir, (byte)iv, (byte)ia); return(colorNuevo); }
public static Vector4 ColorToVector4(Color color) { #if DEBUG Console.WriteLine(color.ToString() + " - (" + color.R.ToString() + ", " + color.G.ToString() + ", " + color.B.ToString() + ", " + color.A.ToString() + ") -> Vec4: " + new Vector4(((float)color.R / 255), ((float)color.G / 255), ((float)color.B / 255), ((float)color.A / 255)).ToString()); #endif return new Vector4(((float)color.R / 255), ((float)color.G / 255), ((float)color.B / 255), ((float)color.A / 255)); }
// Use this for initialization void Start() { Bitmap bitmap = new Bitmap("man_ok.png"); Texture2D tex2D = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false); tex2D.name = Path.GetFileNameWithoutExtension("man_ok.png"); for (int row = 0; row < bitmap.Height; row++) { for (int col = 0; col < bitmap.Width; col++) { System.Drawing.Color srcColor = bitmap.GetPixel(col, row); UnityEngine.Color tgtColor = new UnityEngine.Color(srcColor.R, srcColor.G, srcColor.B, srcColor.A); tex2D.SetPixel(col, row, tgtColor); } } renderer.material.mainTexture = tex2D; System.Drawing.Color srcColor1 = bitmap.GetPixel(100, 100); UnityEngine.Color tgtColor1 = new UnityEngine.Color(srcColor1.R, srcColor1.G, srcColor1.B, srcColor1.A); Debug.Log(tgtColor1.ToString()); Debug.Log(srcColor1.ToString()); tex2D.Apply(); // AssetDatabase.CreateFolder("", "hello"); //AssetDatabase.CreateAsset(tex2D, "dragon.asset"); }
public static string ColorToString(Color color) { string name; if (!MColorNames.TryGetValue(color, out name)) { name = color.ToString(); } return name; }
public override string ToString() { string returnString = Vector.X.ToString("F2") + " " + Vector.Y.ToString("F2") + " " + Vector.Z.ToString("F2"); returnString += " :Color: " + Color.ToString(); return(returnString); }
public System.Drawing.Color ReadValue(string Path, string ValueSection, System.Drawing.Color Default) { string value = this.ReadThisValue(Path, ValueSection, Default.ToString()); value = value.Replace("]", ""); value = value.Replace("Color [", ""); return(System.Drawing.Color.FromName(value)); }
private static String FormatColor(String format, Color arg) { if (String.IsNullOrWhiteSpace(format)) { return arg.ToString(); } var numberFormatInfo = new NumberFormatInfo { NumberDecimalDigits = 1, PercentDecimalDigits = 0, PercentNegativePattern = 1, PercentPositivePattern = 1 }; switch (format) { case "hex": { return String.Format(numberFormatInfo, "#{0:x2}{1:x2}{2:x2}", arg.R, arg.G, arg.B); } case "HEX": { return String.Format(numberFormatInfo, "#{0:X2}{1:X2}{2:X2}", arg.R, arg.G, arg.B); } case "rgb": { return String.Format(numberFormatInfo, "rgb({0}, {1}, {2})", arg.R, arg.G, arg.B); } case "rgb%": { return String.Format(numberFormatInfo, "rgb({0:P}, {1:P}, {2:P})", arg.R / 255d, arg.G / 255d, arg.B / 255d); } case "rgba": { return String.Format(numberFormatInfo, "rgba({0}, {1}, {2}, {3:0.#})", arg.R, arg.G, arg.B, arg.A / 255d); } case "rgba%": { return String.Format(numberFormatInfo, "rgba({0:P}, {1:P}, {2:P}, {3:0.#})", arg.R / 255d, arg.G / 255d, arg.B / 255d, arg.A / 255d); } case "hsl": { return String.Format(numberFormatInfo, "hsl({0:F0}, {1:P}, {2:P})", arg.GetHue(), arg.GetSaturation(), arg.GetBrightness()); } case "hsla": { return String.Format(numberFormatInfo, "hsla({0:F0}, {1:P}, {2:P}, {3:0.#})", arg.GetHue(), arg.GetSaturation(), arg.GetBrightness(), arg.A / 255d); } default: { throw new FormatException(String.Format("Invalid format specified: \"{0}\".", format)); } } }
private void Timer_move_Tick(object sender, EventArgs e) { lock (this) { control.Mowe(panel_game.PointToScreen(panel_game.Location), panel_game.Size); color_paint = Color.FromKnownColor((KnownColor)r.Next(0, typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public) .Select(c => (Color)c.GetValue(null, null)) .ToList().Count)); Color_Box.Items[4] = color_paint.ToString(); } }
private void UpdateAmbientColor(Color aColor) { LogUtil.Write($@"DreamScreen: Setting ambient color to: {aColor.ToString()}."); // Create a list var colors = new List <Color>(); for (var q = 0; q < 12; q++) { colors.Add(aColor); } SendColors(colors, colors); }
public void DrawDirectEdge(Point p1, Point p2, Color c) { Console.WriteLine("DrawDirecEdge with p1 = {0}, p2 = {1}, color = {2}", p1.ToString(), p2.ToString(), c.ToString()); //Graphics g = this.CreateGraphics(); // стрелка Pen p = new Pen(c); //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //g.ScaleTransform( p.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; p.CustomStartCap = new System.Drawing.Drawing2D.AdjustableArrowCap(8, 5, true); //p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; //p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; g.DrawLine(p, p1.X, p1.Y, p2.X, p2.Y); //g.DrawLine(new Pen(c), p) //g.DrawLine(new Pen(c), p) }
public PaintForm() { InitializeComponent(); //initialize event handlers pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown); pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp); pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove); //set default color & thickness thickness = 5; color = Color.Red; //set default text colorLabel.Text = color.ToString(); brushLabel.Text = "Brush Size: " + thickness; //create new bitmap to hold picture data this will allow us to save data image = new Bitmap(pictureBox1.Width, pictureBox1.Height); }
public void UseColor(System.Drawing.Color color) { string materialname = color.ToString(); if (0 == Bindings.vrMaterialAssignKey(materialname)) { Bindings.vrBeginMaterial(materialname); float[] c = new float[4]; c[0] = (float)color.R / 255.0f; c[1] = (float)color.G / 255.0f; c[2] = (float)color.B / 255.0f; c[3] = (float)color.A / 255.0f; Bindings.vrMaterialColor(c); Bindings.vrEndMaterial(); int test = Bindings.vrMaterialAssignKey(materialname); } }
private void PictureBox_MF_Processed_MouseMove(object sender, MouseEventArgs e) { if (threadRaw != null) { return; } TextBox_X_Right.Text = e.Location.X.ToString(); TextBox_Y_Right.Text = e.Location.Y.ToString(); int xOfs = e.Location.X; int yOfs = e.Location.Y; if (rawBitMaps.Count < 1) { return; } Point adjustedPoint = adjustLocationRight(xOfs, yOfs); try { System.Drawing.Color color1 = ((Bitmap)PictureBox_MF_Processed.Image).GetPixel(adjustedPoint.X, adjustedPoint.Y); TextBox_Right_Color.Text = color1.ToString(); TextBox_MF_BrainArea.Text = ""; if (annotateMode == false) { if (partsReference.ContainsKey(color1.R)) { TextBox_MF_BrainArea.Text = partsReference[color1.R]; } } } catch (Exception ex) { TextBox_Right_Color.Text = ""; } }
public static Pen FromSystemColor(Color c) { if (!c.IsSystemColor) { throw new ArgumentException(System.Drawing.SR.GetString("ColorNotSystemColor", new object[] { c.ToString() })); } Pen[] penArray = (Pen[]) SafeNativeMethods.Gdip.ThreadData[SystemPensKey]; if (penArray == null) { penArray = new Pen[0x21]; SafeNativeMethods.Gdip.ThreadData[SystemPensKey] = penArray; } int index = (int) c.ToKnownColor(); if (index > 0xa7) { index -= 0x8d; } index--; if (penArray[index] == null) { penArray[index] = new Pen(c, true); } return penArray[index]; }
public static Brush FromSystemColor(Color c) { if (!c.IsSystemColor) { throw new ArgumentException(System.Drawing.SR.GetString("ColorNotSystemColor", new object[] { c.ToString() })); } Brush[] brushArray = (Brush[]) SafeNativeMethods.Gdip.ThreadData[SystemBrushesKey]; if (brushArray == null) { brushArray = new Brush[0x21]; SafeNativeMethods.Gdip.ThreadData[SystemBrushesKey] = brushArray; } int index = (int) c.ToKnownColor(); if (index > 0xa7) { index -= 0x8d; } index--; if (brushArray[index] == null) { brushArray[index] = new SolidBrush(c, true); } return brushArray[index]; }
/// <summary> /// draws text label on a chart. /// if price is less than zero (MinPrice), all labels are cleared. /// </summary> /// <param name="price"></param> /// <param name="bar"></param> /// <param name="label"></param> public void DrawChartLabel(decimal price, int time, string label, Color color) { // reject if we don't have bars yet if (bl == null) { debug("No bars, ignoring draw label "+price+" at "+time+" "+label+" color: "+color.ToString()); return; } // test whether this is an oscilator if (isosccolor(color)) { DrawOscLabel(price, time, label, color); return; } // otherwise treat as a price // invalid price allows user to clear all price labels if (price < MinPrice) { _colpoints.Remove(color); _collineend.Remove(color); return; } List<Label> tmp; // setup this label if we don't have points for it already if (!_colpoints.TryGetValue(color, out tmp)) { tmp = new List<Label>(); _colpoints.Add(color, tmp); _collineend.Add(color,new List<int>()); } // create new point for this label Label l = new Label(time, price, label, color); // mark whether it has text labels hastextlabels |= !l.isLine; // add it so it can be drawn with DrawLabels _colpoints[color].Add(l); // if label represents a line (rather than text), add it to label's line if (l.isLine) _collineend[color].Add(_colpoints[color].Count-1); }
private Image LoadTreeViewAdvResourceImage(String name, String type, Color color) { String key = String.Format("{0};{1};{2}", name, type, color.ToString()); if (_cached_icons.ContainsKey(key)) return _cached_icons[key]; Bitmap bm = null; if (name == "FolderClosed") bm = new Bitmap(DicomDumpResources.FolderClosed); else if (name == "Folder") bm = new Bitmap(DicomDumpResources.Folder); else bm = new Bitmap(DicomDumpResources.Leaf); bm.MakeTransparent(); Graphics g = Graphics.FromImage(bm); Brush b = new SolidBrush(color); if (_cached_font == null) { _cached_font = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Regular); } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.None; g.DrawString(type, _cached_font, b, new RectangleF(-2, 0, bm.Width + 5, bm.Height), sf); _cached_icons.Add(key, bm); return bm; }
protected override void InternalSetBackgroundColor(Color value) { InternalStyler.TargetInnerBorder.style.backgroundColor = value.ToString(); ContentContainerPadding.style.backgroundColor = value.ToString(); //TargetOuterBorder.style.backgroundColor = value.ToString(); //ContentContainer.style.backgroundColor = value.ToString(); //// for firefox fullscren //TargetNoBorder.style.backgroundColor = value.ToString(); }
/// <summary> /// Retrieves a <see cref="TextureAsset"/> (creating it if necessary) filled with the given color. /// </summary> /// <param name="color">The color to fill the texture with.</param> /// <returns>A texture asset filled with the given color.</returns> public TextureAsset GetColorTexture(Color color) { string key = ':' + color.ToString(); // The ':' is to make absolutely sure that the key isn't a valid filename. return GetCreateAsset(AssetType.Texture, key, assetCore => new TextureAsset(assetCore as TextureAssetCore), () => new ColorTextureAssetCore(color)) as TextureAsset; }
private string GetHtmlColor(Color color) { if (color.IsEmpty == true) { return string.Empty; } if (color.IsNamedColor == true) { return color.ToKnownColor().ToString(); } if (color.IsSystemColor == true) { return color.ToString(); } return "#" + color.ToArgb().ToString("x").Substring(2); }
public static Image StaticTakeScreenshot(String MovieURL, Size Size, int FrameNum = 0, FlashScaleMode ScaleMode = FlashScaleMode.showAll, Color? BackgroundColor = null) { var flash = new ExAxShockwaveFlash(); //IFormatter formatter = new BinaryFormatter(); //var state = (AxHost.State)formatter.Deserialize(new MemoryStream(OcxData)); //Console.WriteLine(state); if (!File.Exists(MovieURL)) throw(new Exception("Flash Movie '" + MovieURL + "' doesn't exists.")); String Hash = "ExAxShockwaveFlashCache_" + MD5Hex(MovieURL) + "_" + MD5Hex(File.GetLastWriteTimeUtc(MovieURL).ToString()) + "_" + Size.Width + "x" + Size.Height + "_" + FrameNum + "_" + ScaleMode + "_" + MD5Hex(BackgroundColor.ToString()); String CacheTempFile = Path.GetTempPath() + @"\" + Hash + ".bmp"; if (File.Exists(CacheTempFile)) { return Image.FromFile(CacheTempFile); } var tempForm = new Form(); tempForm.BackColor = Color.White; flash.BeginInit(); { tempForm.Controls.Add(flash); flash.Size = Size; //flash.Visible = false; } flash.EndInit(); //flash.PreferredSize = Size; flash.LoadMovie(0, MovieURL); flash.Size = Size; flash.Quality = 1; flash.GotoFrame(FrameNum); flash.ScaleMode = (int)ScaleMode; //flash.BGColor = "ffffff"; if (BackgroundColor.HasValue) { //Console.WriteLine(BackgroundColor); //Console.WriteLine(BackgroundColor.Value.R); //flash.BGColor = "ffffff"; //flash.WMode = "Window"; //flash.BackColor = Color.White; //flash.BackgroundColor = BackgroundColor.Value.ToArgb(); flash.BackgroundColor = (BackgroundColor.Value.R << 0) | (BackgroundColor.Value.G << 8) | (BackgroundColor.Value.B << 16); } else { flash.WMode = "Transparent"; //Console.WriteLine("Transparent"); } //Thread.Sleep(20); Bitmap Screenshot = flash.TakeScreenshot(Size); flash.Dispose(); tempForm.Dispose(); Screenshot.Save(CacheTempFile); return Screenshot; }
public void LogSensorData(string sensorlog, Color data) { string standardfilename = sensorlog + DateTime.Now.ToString("_d MMM y") + ".txt"; string sensorfilename = MakeNameUnique(standardfilename); string filepath = System.IO.Path.Combine(activeDir, sensorfilename); if (!File.Exists(filepath)) { FileStream fs = File.Create(filepath); fs.Close(); } else { }//end else File.AppendAllText(filepath, data.ToString() + System.Environment.NewLine); }
public ColorTextureAssetCore(Color color) : base(color.ToString()) { _color = color; _maxU = 1.0f; _maxV = 1.0f; }
public Pen GetSizedPen (Color color, int size) { string hash = color.ToString () + size; lock (sizedpens) { Pen res = sizedpens [hash] as Pen; if (res != null) return res; Pen pen = new Pen (color, size); sizedpens [hash] = pen; return pen; } }
public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor) { string hash = ((int)hatchStyle).ToString () + foreColor.ToString () + backColor.ToString (); lock (hatchbrushes) { HatchBrush brush = (HatchBrush) hatchbrushes[hash]; if (brush == null) { brush = new HatchBrush (hatchStyle, foreColor, backColor); hatchbrushes.Add (hash, brush); } return brush; } }
protected void SetColorImage(Color c, Button b) { Image colorImage = new Bitmap(COLOR_IMAGE_SIZE, COLOR_IMAGE_SIZE); Graphics g = Graphics.FromImage(colorImage); g.Clear(c); g.Dispose(); b.Image = colorImage; b.Text = c.ToString(); b.ImageAlign = ContentAlignment.MiddleLeft; b.TextAlign = ContentAlignment.MiddleRight; }
public Pen GetDashPen (Color color, DashStyle dashStyle) { string hash = color.ToString() + dashStyle; lock (dashpens) { Pen res = dashpens [hash] as Pen; if (res != null) return res; Pen pen = new Pen (color); pen.DashStyle = dashStyle; dashpens [hash] = pen; return pen; } }
public Color GetColor(XmlNode parentNode, String id, Color default_val) { XmlNode nd = FindChildElement(parentNode, id); Color result; if (nd == null) { AddParameter(parentNode, id, default_val.ToString()); return default_val; } try { result = ParseColor(nd.InnerText); } catch (Exception) { LogParamErr(parentNode, id, "color value"); result = default_val; } return result; }
public override string ToString() { return(color.ToString()); }
private void picBox_MouseMove(object sender, MouseEventArgs e) { label1.Text = e.Location.ToString(); //获取图像单个像素数据 try { pixel = MyImage.GetPixel(e.Location.X, e.Location.Y); label2.Text = pixel.ToString(); } catch { } }
/// <summary> /// Loads a site specific border bitmap file and returns the bitmap object /// </summary> /// <param name="color"></param> /// <param name="site"></param> /// <returns></returns> public static Bitmap GetBorderBitmap(Color color, Site site, int width, int height) { Bitmap b = null; switch(site) { case Site.Party: b = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(b); g.FillRectangle(new SolidBrush(color), 0, 0, b.Width, b.Height); g.FillRectangle(new SolidBrush(Color.Black), Settings.ActiveTableBorderWidth, Settings.ActiveTableBorderWidth, b.Width - (Settings.ActiveTableBorderWidth * 2), b.Height - (Settings.ActiveTableBorderWidth * 2)); g.Save(); return b; } if(b == null) throw new Exception("Tried to get border with unknown color: " + color.ToString()); return b; }
public static Pen FromSystemColor(Color c) { if (!c.IsSystemColor) { throw new ArgumentException(SR.GetString(SR.ColorNotSystemColor, c.ToString())); } Pen[] systemPens = (Pen[])SafeNativeMethods.Gdip.ThreadData[SystemPensKey]; if (systemPens == null) { systemPens = new Pen[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen]; SafeNativeMethods.Gdip.ThreadData[SystemPensKey] = systemPens; } int idx = (int)c.ToKnownColor(); if (idx > (int)KnownColor.YellowGreen) { idx -= (int)KnownColor.YellowGreen - (int)KnownColor.WindowText; } idx--; Debug.Assert(idx >= 0 && idx < systemPens.Length, "System colors have been added but our system color array has not been expanded."); if (systemPens[idx] == null) { systemPens[idx] = new Pen(c, true); } return systemPens[idx]; }
private char GetSymbol(Color color, Settings settings) { char symbol; if (!settings.ColorSymbolRelation.TryGetValue(color, out symbol)) throw new Exception("There are no value for this key, key = " + color.ToString()); return symbol; }
private ListViewItem CreateColorListItem(Color colorItem) { Bitmap result = new Bitmap(48, 48); Graphics gfx = Graphics.FromImage(result); using (SolidBrush brush = new SolidBrush(colorItem)) { using (var p = new Pen(ThemeColorTable.BorderColor, 2)) { gfx.FillRectangle(brush, 0, 0, 48, 48); gfx.DrawRectangle(p, 0, 0, 48, 48); } } gfx.Dispose(); listViewColors.LargeImageList.Images.Add(colorItem.ToString(), result); ListViewItem item = new ListViewItem { ToolTipText = string.Format("R: {0} G: {1} B: {2}", colorItem.R, colorItem.G, colorItem.B), ImageKey = colorItem.ToString(), Tag = colorItem, ForeColor = ThemeColorTable.ForeColor }; return item; }
public static string GetColourDescription(Color c, bool orig) { if (c.Equals(Color.Transparent)) { return "Transparent"; } //get matching var bc = Beads.AllBeadColours.Where(s => ColorExtras.Equals(s.Value, c)).ToList(); if (!bc.Any()) return c.ToString(); var bcf = bc.First(); return bcf.Key + " " + bcf.Value; }
public static int FindNextColor(Color c, Color[] palette, decimal threshold = 0) { int id = -1; decimal min_distance = (decimal)Math.Sqrt(3) * 255; // Set the max distance double module = Math.Sqrt(c.R * c.R + c.G * c.G + c.B * c.B); for (int i = 1; i < palette.Length; i++) { double modulec = Math.Sqrt(palette[i].R * palette[i].R + palette[i].G * palette[i].G + palette[i].B * palette[i].B); decimal distance = (decimal)Math.Abs(module - modulec); if (distance < min_distance) { min_distance = distance; id = i; } } if (min_distance > threshold) // If the distance it's bigger than wanted id = -1; // If still it doesn't found the color try with the first one, usually is transparent so for this reason we leave it to the end if (id == -1) { double modulec = Math.Sqrt(palette[0].R * palette[0].R + palette[0].G * palette[0].G + palette[0].B * palette[0].B); decimal distance = (decimal)Math.Abs(module - modulec); if (distance <= threshold) id = 0; } if (id == -1) { Console.Write("Color not found: "); Console.WriteLine(c.ToString() + " (distance: " + min_distance.ToString() + ')'); } return id; }
private void CheckWin() { int x, y; System.Drawing.Color winningColor = lblTurn.BackColor; System.Drawing.Color blank = lblTurn.BackColor; bool win = false; //Horizontal checking for (y = 0; y < 6; y++) { for (x = 0; x < 4; x++) { if (Board[x][y].BackColor == Board[x + 1][y].BackColor && Board[x + 1][y].BackColor == Board[x + 2][y].BackColor && Board[x + 2][y].BackColor == Board[x + 3][y].BackColor && Board[x][y].BackColor != blank && Board[x + 1][y].BackColor != blank && Board[x + 2][y].BackColor != blank && Board[x + 3][y].BackColor != blank) { winningColor = Board[x][y].BackColor; win = true; break; } } if (win) { if (p1p.Color.ToString() == winningColor.ToString()) { p1p.GamesWon += 1; lblWins1.Text = p1p.Name + " won " + p1p.GamesWon + " times total."; MessageBox.Show(p1p.Name + " wins!"); clearBoard(); win = false; } else if (p2p.Color.ToString() == winningColor.ToString()) { p2p.GamesWon += 1; lblWins2.Text = p2p.Name + " won " + p2p.GamesWon + " times total."; MessageBox.Show(p2p.Name + " wins!"); win = false; clearBoard(); } else { win = false; } break; } } //Vertical Checking if (win == false) { for (x = 0; x < 7; x++) { for (y = 0; y < 3; y++) { if (Board[x][y].BackColor == Board[x][y + 1].BackColor && Board[x][y + 1].BackColor == Board[x][y + 2].BackColor && Board[x][y + 2].BackColor == Board[x][y + 3].BackColor && Board[x][y].BackColor != blank && Board[x][y + 1].BackColor != blank && Board[x][y + 2].BackColor != blank && Board[x][y + 3].BackColor != blank) { winningColor = Board[x][y].BackColor; win = true; break; } } if (win) { if (p1p.Color.ToString() == winningColor.ToString()) { p1p.GamesWon += 1; lblWins1.Text = p1p.Name + " won " + p1p.GamesWon + " times total."; MessageBox.Show(p1p.Name + " wins!"); win = false; clearBoard(); } else if (p2p.Color.ToString() == winningColor.ToString()) { p2p.GamesWon += 1; lblWins2.Text = p2p.Name + " won " + p2p.GamesWon + " times total."; MessageBox.Show(p2p.Name + " wins!"); win = false; clearBoard(); } else { win = false; } break; } } } //Downward Diagonal Checking if (win == false) { for (x = 0; x < 4; x++) { for (y = 0; y < 3; y++) { if (Board[x][y].BackColor == Board[x + 1][y + 1].BackColor && Board[x + 1][y + 1].BackColor == Board[x + 2][y + 2].BackColor && Board[x + 2][y + 2].BackColor == Board[x + 3][y + 3].BackColor && Board[x][y].BackColor != blank && Board[x + 1][y + 1].BackColor != blank && Board[x + 2][y + 2].BackColor != blank && Board[x + 3][y + 3].BackColor != blank) { winningColor = Board[x][y].BackColor; win = true; break; } } if (win) { if (p1p.Color.ToString() == winningColor.ToString()) { p1p.GamesWon += 1; lblWins1.Text = p1p.Name + " won " + p1p.GamesWon + " times total."; MessageBox.Show(p1p.Name + " wins!"); win = false; clearBoard(); } else if (p2p.Color.ToString() == winningColor.ToString()) { p2p.GamesWon += 1; lblWins2.Text = p2p.Name + " won " + p2p.GamesWon + " times total."; MessageBox.Show(p2p.Name + " wins!"); win = false; clearBoard(); } else { win = false; } break; } } } //Upward Diagonal Checking if (win == false) { for (y = 3; y < 6; y++) { for (x = 0; x < 4; x++) { if (Board[x][y].BackColor == Board[x + 1][y - 1].BackColor && Board[x + 1][y - 1].BackColor == Board[x + 2][y - 2].BackColor && Board[x + 2][y - 2].BackColor == Board[x + 3][y - 3].BackColor && Board[x][y].BackColor != blank && Board[x + 1][y - 1].BackColor != blank && Board[x + 2][y - 2].BackColor != blank && Board[x + 3][y - 3].BackColor != blank) { winningColor = Board[x][y].BackColor; win = true; break; } } if (win) { if (p1p.Color.ToString() == winningColor.ToString()) { p1p.GamesWon += 1; lblWins1.Text = p1p.Name + " won " + p1p.GamesWon + " times total."; MessageBox.Show(p1p.Name + " wins!"); win = false; clearBoard(); } else if (p2p.Color.ToString() == winningColor.ToString()) { p2p.GamesWon += 1; lblWins2.Text = p2p.Name + " won " + p2p.GamesWon + " times total."; MessageBox.Show(p2p.Name + " wins!"); win = false; clearBoard(); } else { win = false; } break; } } } }
public Bitmap Rendering(string bmpPath, byte _Alpha, byte _Red, byte _Green, byte _Blue, bool Out) { /// <summary> /// This function is the "heart" of the program. It get's the pixels via LockBits, manipulates them /// then adds then to the picture. This is, in my mind, the most efficent way to do this. /// I have tested a 3987x2459 and it rendered in less than a second, so it is very fast. /// </summary> string PathWay = Path.GetDirectoryName(bmpPath) + "\\" + Path.GetFileNameWithoutExtension(bmpPath) + ".txt"; Bitmap imageFile = new Bitmap(bmpPath); BitmapData imageData = new BitmapData(); IntPtr Pointer; imageData = imageFile.LockBits(new Rectangle(0, 0, imageFile.Width, imageFile.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Pointer = imageData.Scan0; int ArraySize = Math.Abs(imageData.Stride) * imageFile.Height; byte[] PixelArray = new byte[ArraySize]; Marshal.Copy(Pointer, PixelArray, 0, ArraySize); int PixelAmount = 4; //ArGb Color ArGBformat = new Color(); byte NewAlpha; byte NewRed; byte NewGreen; byte NewBlue; StreamWriter Save = new StreamWriter(PathWay); unsafe { for (int y = 0; y < imageData.Height; y++) { byte* row = (byte*)imageData.Scan0 + (y * imageData.Stride); for (int x = 0; x < imageData.Width; x++) { int offSet = x * PixelAmount; // read pixel byte blue = row[offSet]; byte green = row[offSet + 1]; byte red = row[offSet + 2]; byte alpha = row[offSet + 3]; //Manipulates pixel NewAlpha = (byte)Math.Abs(alpha - _Alpha); //Do not work NewRed = (byte)Math.Abs(red - _Red); NewBlue = (byte)Math.Abs(blue - _Blue); NewGreen = (byte)Math.Abs(green - _Green); //Sets image row[offSet] = NewBlue; row[offSet + 1] = NewGreen; row[offSet + 2] = NewRed; row[offSet + 3] = NewAlpha; ArGBformat = Color.FromArgb(NewAlpha, NewRed, NewGreen, NewBlue); if (Out) { byte[] ConvertToByte = GetBytes(ArGBformat.ToString()); string ConvertToString = GetString(ConvertToByte); Save.Write(ConvertToString); } } } Save.Flush(); Save.Dispose(); imageFile.UnlockBits(imageData); return imageFile; } }
/// <summary> /// Set task over color /// </summary> /// <param name="col">task over color</param> public void SetTaskOverColor(Color col) { settingInfo.misc.TaskOverColor = col; EventHandlers.UpdateSettings(settingInfo); string loggerString = string.Format("User set task over color to {0}..", col.ToString()); Logger.Info(loggerString, "Logc::Settings"); }