private void GetRandomFlagColors_LoadExisting(IEnumerable<ColorHSV> existing, ColorHSV[] retVal, List<Tuple<ColorHSV, FlagColorCategory>> categorized) { if (existing == null) { return; } int index = 0; foreach (ColorHSV color in existing) { if (index >= retVal.Length) { break; } retVal[index] = color; categorized.Add(Tuple.Create(color, Categorize(color))); index++; } }
public ColorHSV GetRandomColor(FlagColorCategory category, double? hue = null) { Random rand = StaticRandom.GetRandomForThread(); double hueActual = hue ?? rand.NextDouble(360); ColorHSV retVal; if (category == FlagColorCategory.Other) { // This category is under other category rectangles, so do a brute force repeat until match FlagColorCategory cat; do { retVal = new ColorHSV(hueActual, rand.NextDouble(100), rand.NextDouble(100)); cat = Categorize(retVal); } while (cat != category); } else { // The color range is stored as a rectangle (X is saturation, Y is value) Rect catRect = this.Categories.First(o => o.Item2 == category).Item1; retVal = new ColorHSV(hueActual, rand.NextDouble(catRect.Left, catRect.Right), rand.NextDouble(catRect.Top, catRect.Bottom)); } return retVal; }
public ColorHSV[] GetRandomFlagColors(int count, IEnumerable<ColorHSV> existing = null) { if (count > _maxFlagColors) { throw new ArgumentOutOfRangeException(string.Format("Can't create that many colors: {0}. Max allowed: {1}", count.ToString(), _maxFlagColors.ToString())); } ColorHSV[] retVal = new ColorHSV[count]; var categorized = new List<Tuple<ColorHSV, FlagColorCategory>>(); GetRandomFlagColors_LoadExisting(existing, retVal, categorized); int index = categorized.Count; for (int cntr = 0; cntr < count; cntr++) { var color = GetRandomFlagColors_Next(categorized); retVal[cntr] = color.Item1; categorized.Add(color); } return retVal; }
/// <summary> /// Creates or adds to a set of colors to be used by klinth weapons /// </summary> /// <param name="existing">This is a material definition that may already exist, or partially filled out</param> /// <param name="basedOn">This is a way to force the return hue (a spike ball's colors could be based on the handle's colors)</param> public static MaterialDefinition[] GetRandomMaterials_Klinth(MaterialDefinition[] existing = null, ColorHSV? basedOn = null) { List<MaterialDefinition> retVal = new List<MaterialDefinition>(); Random rand = StaticRandom.GetRandomForThread(); if (existing != null) { retVal.AddRange(existing); } // Main color (in the case of a handle, the only color) if (retVal.Count < 1) { double hue; if (basedOn == null) { hue = StaticRandom.NextDouble(0, 360); } else { //hue = GetRandomHue(basedOn.Value.H); hue = basedOn.Value.H; // klinth shouldn't allow an opposite hue (it looks really bad) } retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.HSVtoRGB(hue, StaticRandom.NextDouble(50, 80), StaticRandom.NextDouble(40, 90)).ToHex(), SpecularColor = UtilityWPF.HSVtoRGB(StaticRandom.NextDouble(0, 360), StaticRandom.NextDouble(50, 80), StaticRandom.NextDouble(40, 90)).ToHex(), EmissiveColor = UtilityWPF.GetRandomColor(0, 255).ToHex() }); } // Secondary color (in the case of ball and spikes, this is the spikes) if (retVal.Count < 2) { ColorHSV firstDiff = UtilityWPF.ColorFromHex(retVal[0].DiffuseColor).ToHSV(); ColorHSV firstSpec = UtilityWPF.ColorFromHex(retVal[0].SpecularColor).ToHSV(); ColorHSV firstEmis = UtilityWPF.ColorFromHex(retVal[0].EmissiveColor).ToHSV(); // Needs to be roughly the same color as the ball, just a bit darker retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.HSVtoRGB(firstDiff.H, firstDiff.S * 1.25, firstDiff.V * .66d).ToHex(), SpecularColor = UtilityWPF.HSVtoRGB(firstSpec.H, firstSpec.S * 1.1, firstSpec.V).ToHex(), EmissiveColor = UtilityWPF.HSVtoRGB(firstEmis.H, firstEmis.S, firstEmis.V).ToHex(), }); } return retVal.ToArray(); }
public FlagColorCategory Categorize(ColorHSV color) { Point colorPoint = new Point(color.S, color.V); //NOTE: The rectangle could overlap, but the array is built in order with the intention that the first to match wins foreach (var category in this.Categories) { if (category.Item1.Contains(colorPoint)) { return category.Item2; } } throw new ApplicationException("Should have found one"); }
/// <summary> /// Creates or adds to a set of colors to be used by composite weapons /// </summary> /// <param name="existing">This is a material definition that may already exist, or partially filled out</param> /// <param name="basedOn">This is a way to force the return hue (a spike ball's colors could be based on the handle's colors)</param> public static MaterialDefinition[] GetRandomMaterials_Composite(MaterialDefinition[] existing = null, ColorHSV? basedOn = null) { List<MaterialDefinition> retVal = new List<MaterialDefinition>(); Random rand = StaticRandom.GetRandomForThread(); if (existing != null) { retVal.AddRange(existing); } if (retVal.Count < 1) { if (basedOn == null) { // For the first one, just pick any random color retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.GetRandomColor(0, 255).ToHex() }); } else { // Make this based on the hue of the color passed in retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.HSVtoRGB(GetRandomHue(basedOn.Value.H), rand.NextDouble(100), rand.NextDouble(100)).ToHex() }); } } ColorHSV first = UtilityWPF.ColorFromHex(retVal[0].DiffuseColor).ToHSV(); if (retVal.Count < 2) { retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.HSVtoRGB(GetRandomHue(first.H), rand.NextDouble(100), rand.NextDouble(100)).ToHex() }); } if (retVal.Count < 3) { retVal.Add(new MaterialDefinition() { DiffuseColor = UtilityWPF.HSVtoRGB(GetRandomHue(first.H), rand.NextDouble(100), rand.NextDouble(100)).ToHex() }); } return retVal.ToArray(); }
public NetworkOutputs(string[] names) { this.Size = names.Length; this.Names = names; this.DistanceMult = 1.5d / Math.Sqrt(this.Size); // the 1.5 doesn't mean anything. It just helps push them apart a little more this.Hues = CreateHues(this.Size); #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); // Colors this.DotColors = this.Hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return new Tuple<ColorHSV, Material>(color, material); }).ToArray(); // Gray this.ColorGray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(this.ColorGray.ToRGB()))); material_Gray.Children.Add(specular); this.DotGray = material_Gray; #endregion }
private static Item3D[] DrawBrainIOLinks3D(Viewport3D viewport, Tuple<int, int>[] links, Item3D[] items1, Item3D[] items2, Color defaultColor, bool isRainbow) { const double THICKNESS = .025; if (!isRainbow) { var lines = links.Select(o => Tuple.Create(items1[o.Item1].Position.Value, items2[o.Item2].Position.Value)); return new[] { new Item3D(AddLines(viewport, lines, defaultColor, THICKNESS)), }; } List<Item3D> retVal = new List<Item3D>(); foreach (var byItem1 in links.ToLookup(o => o.Item1)) { //Color color = UtilityWPF.GetRandomColor(150, 220); Color color = new ColorHSV(StaticRandom.NextDouble(360), 60, 100).ToRGB(); var lines = byItem1.Select(o => Tuple.Create(items1[byItem1.Key].Position.Value, items2[o.Item2].Position.Value)); retVal.Add(new Item3D(AddLines(viewport, lines, color, THICKNESS))); } return retVal.ToArray(); }
private static GeometryModel3D GetEggModel(Point3D position, double radius, BotShellColorsDNA colors) { // Material MaterialGroup material = new MaterialGroup(); Color baseColor = UtilityWPF.ColorFromHex(colors.InnerColorDiffuse); ColorHSV driftedColor = baseColor.ToHSV(); driftedColor = new ColorHSV(UtilityWPF.GetCappedAngle(driftedColor.H + (colors.DiffuseDrift * StaticRandom.NextDouble(0, 4))), driftedColor.S, driftedColor.V); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(driftedColor.ToRGB()))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80FFFFFF")), 20)); material.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("20" + colors.EmissiveColor.Substring(colors.EmissiveColor.Length - 6))))); // Geometry Model GeometryModel3D retVal = new GeometryModel3D(); retVal.Material = material; retVal.BackMaterial = material; retVal.Geometry = UtilityWPF.GetSphere_LatLon(5, radius); Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new ScaleTransform3D(new Vector3D(.75d, .75d, 1d))); transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); retVal.Transform = transform; return retVal; }
private static Visual3D TestSamples_Draw(SketchSample[] sketches, double[] hues) { const double RADIUS = .5; const double DOTRADIUS = .035; #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); var material_Color = hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return new { Color = color, Material = material }; }).ToArray(); ColorHSV color_Gray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(color_Gray.ToRGB()))); material_Gray.Children.Add(specular); #endregion Model3DGroup group = new Model3DGroup(); foreach (SketchSample sketch in sketches) { int? matchIndex = UtilityEncog.IsMatch(sketch.NNOutput); Material material; if (matchIndex == null) { sketch.IsMatch = false; sketch.Color = color_Gray; material = material_Gray; } else { sketch.IsMatch = true; sketch.Color = material_Color[matchIndex.Value].Color; material = material_Color[matchIndex.Value].Material; } sketch.Position = Math3D.GetRandomVector_Spherical(RADIUS).ToPoint(); sketch.Translate_3DDot = new TranslateTransform3D(sketch.Position.ToVector()); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_Ico(DOTRADIUS, 1, true); geometry.Transform = sketch.Translate_3DDot; group.Children.Add(geometry); } ModelVisual3D visual = new ModelVisual3D(); visual.Content = group; return visual; }