public static void PaintFlood(PaintedHillsMod mymod, Colorer colorer, int tile_x, int tile_y, Paints hue) { var peek = new Dictionary <int, ISet <int> >(); peek[tile_x] = new HashSet <int>(); peek[tile_x].Add(tile_y); do { foreach (int x in peek.Keys) { foreach (int y in peek[x]) { colorer.ColorTile(mymod, x, y); } } int[] peek_x = peek.Keys.ToArray(); foreach (int x in peek_x) { int[] peek_y = peek[x].ToArray(); foreach (int y in peek_y) { AreaPainter.PeekAdjacentClearTiles(colorer.HueMap, peek, x, y); peek[x].Remove(y); } if (peek[x].Count == 0) { peek.Remove(x); } } } while(peek.Count > 0); }
public SKSize Measure(Colorer colorer, float pointSize, Style style) { var sizeX = 0.0f; var sizeY = 0.0f; using (var paint = colorer.TextPaint(colorer.fixedFont, pointSize, SKColors.Black)) { foreach (SpeciesValue sp in sample.stateMap.species) { var r = colorer.MeasureText(sp.Format(style) + " = " + Gui.FormatUnit(sample.stateMap.Mean(sp.symbol), " ", "M", style.numberFormat), paint); sizeX = Math.Max(sizeX, r.Width); sizeY += pointSize; } sizeY += pointSize; foreach (var reaction in this.reactions) { var r = colorer.MeasureText(reaction.TopFormat(style), paint); sizeX = Math.Max(sizeX, r.Width); sizeY += pointSize; } sizeY += pointSize; foreach (var trigger in this.sample.Triggers(style)) { var r = colorer.MeasureText(trigger.Format(style), paint); sizeX = Math.Max(sizeX, r.Width); sizeY += pointSize; } } return(new SKSize(sizeX, sizeY)); }
void ValueToARGB(uint value, byte alpha, byte red, byte green, byte blue) { Colorer.ValueToARGB(value, out var alphaOut, out var redOut, out var greenOut, out var blueOut); Assert.AreEqual(alpha, alphaOut); Assert.AreEqual(red, redOut); Assert.AreEqual(green, greenOut); Assert.AreEqual(blue, blueOut); }
public virtual ImageBox Color(ColorMatrix colorMatrix) { var result = new Colorer(Image).Color(colorMatrix); Image.Dispose(); Image = result; return(this); }
static string OverlayColor(string color1, string color2) { Colorer.StringToARGB(color1, out byte alpha1, out byte red1, out byte green1, out byte blue1); Colorer.StringToARGB(color2, out byte alpha2, out byte red2, out byte green2, out byte blue2); red1 = (byte)((red1 * alpha1 / 255) + (red2 * alpha2 * (255 - alpha1) / (255 * 255))); green1 = (byte)((green1 * alpha1 / 255) + (green2 * alpha2 * (255 - alpha1) / (255 * 255))); blue1 = (byte)((blue1 * alpha1 / 255) + (blue2 * alpha2 * (255 - alpha1) / (255 * 255))); alpha1 = (byte)(alpha1 + (alpha2 * (255 - alpha1) / 255)); return(Colorer.ARGBToString(alpha1, red1, green1, blue1)); }
static string AddColor(string color1, string color2) { Colorer.StringToARGB(color1, out var alpha1, out var red1, out var green1, out var blue1); Colorer.StringToARGB(color2, out var alpha2, out var red2, out var green2, out var blue2); alpha1 = (byte)Math.Max(0, Math.Min(alpha1 + alpha2, 255)); red1 = (byte)Math.Max(0, Math.Min(red1 + red2, 255)); green1 = (byte)Math.Max(0, Math.Min(green1 + green2, 255)); blue1 = (byte)Math.Max(0, Math.Min(blue1 + blue2, 255)); return(Colorer.ARGBToString(alpha1, red1, green1, blue1)); }
public static void PaintBlob(PaintedHillsMod mymod, Colorer colorer, int tile_x, int tile_y, float size, float size_variance, float shape_variance) { IDictionary <float, float> rays = RayPainter.GetChunkRays(size, size_variance, shape_variance); //if( (mymod.DEBUGFLAGS & 1) != 0 ) { // ErrorLogger.Log( JsonConfig<IDictionary<float, float>>.Serialize( rays ) ); //} //PaintRays.PaintRadiationEdges( huemap, tile_x, tile_y, rays, hue, new Painter(PaintBasic.PaintTile) ); //foreach( float rad in rays.Keys ) { // PaintRays.PaintRay( huemap, tile_x, tile_y, rad, rays[rad], hue, new Painter( PaintArea.PaintFlood ) ); //} RayPainter.PaintRadiation(mymod, colorer, tile_x, tile_y, rays); }
ImageGrabColorDialog(string color) { InitializeComponent(); try { Colorer.StringToARGB(color, out var alpha, out var red, out var green, out var blue); Alpha = alpha; Red = red; Green = green; Blue = blue; } catch { Alpha = Red = Green = Blue = 255; } }
public void InitLine() { XLine.SetLeftTopAlignment(); XLine.MakeCellIndependent(SchemeView.GridSize); XLine.Fill = Colorer.GetBrushByValue(null); XLine.StrokeThickness = WireThickness; XLine.Tapped += (_, _) => Tapped(this); XLine.PointerEntered += (_, _) => XLine.StrokeThickness *= 2; XLine.PointerExited += (_, _) => XLine.StrokeThickness /= 2; XLine.Stroke = new SolidColorBrush(Colors.Wheat); XLine.Fill = new SolidColorBrush(Colors.Wheat); }
public void SetValues() { TimeSpan diff = DateTime.Now - StartTime; Vector3 col = new Vector3(1, 1, 1); float Alpha = 1.0f; if (Colorer.HasAnimData()) { col = Colorer.GetValueForAnim((int)diff.TotalMilliseconds); } if (AlphaGen.HasAnimData()) { Alpha = AlphaGen.GetValueForAnim((int)diff.TotalMilliseconds) / (float)0x7FFF; } }
static string AdjustColor(string color, double multiplier, bool doAlpha, bool doRed, bool doGreen, bool doBlue) { Colorer.StringToARGB(color, out var alpha, out var red, out var green, out var blue); if (doAlpha) { alpha = (byte)Math.Max(0, Math.Min((int)(alpha * multiplier + 0.5), 255)); } if (doRed) { red = (byte)Math.Max(0, Math.Min((int)(red * multiplier + 0.5), 255)); } if (doGreen) { green = (byte)Math.Max(0, Math.Min((int)(green * multiplier + 0.5), 255)); } if (doBlue) { blue = (byte)Math.Max(0, Math.Min((int)(blue * multiplier + 0.5), 255)); } return(Colorer.ARGBToString(alpha, red, green, blue)); }
public static Material Generate(float Base1, float Variance, float freq, int seed) { const int texSize = 256; Texture2D text = new Texture2D(texSize, texSize, TextureFormat.RGB24, true); Color aColor; for (int y = 0; y < text.height; ++y) { for (int x = 0; x < text.width; ++x) { aColor = Colorer.Generate(x, y, freq, Base1, Variance, seed); text.SetPixel(x, y, aColor); } } text.Apply(); Material mat = new Material(Resources.Load <Material>("Diffuse")); mat.mainTexture = text; return(mat); }
public static void PaintRadiation(PaintedHillsMod mymod, Colorer colorer, int tile_x, int tile_y, IDictionary <float, float> ray_rads_and_lengths) { float steps = mymod.Config.HueBlobMinimumTileRadius; var rays = new SortedSet <float>(ray_rads_and_lengths.Keys); for (int i = 0; i < 60; i++) { float curr_rad = RayPainter.GetRadianAt(i % 60); float next_rad = RayPainter.GetRadianAt((i + 1) % 60); float curr_range = ray_rads_and_lengths[curr_rad]; float range_span = curr_range - ray_rads_and_lengths[next_rad]; //ErrorLogger.Log( "x: "+tile_x+", y: "+tile_y+", rad: "+curr_rad+", nextrad: "+next_rad+", range: "+curr_range+", span: "+range_span); for (float j = 0; j < steps; j += 1f) { float step_rad = curr_rad + RayPainter.GetRadianAt(j / steps); float step_range = curr_range + (range_span * (j / steps)); colorer.ColorTileRay(mymod, tile_x, tile_y, step_rad, step_range); } } }
public static void PaintRadiationEdges(PaintedHillsMod mymod, Colorer colorer, int tile_x, int tile_y, IDictionary <float, float> ray_rads_and_lengths) { Vector2 tile_origin = new Vector2(tile_x, tile_y); Vector2 beg_pos = Vector2.Zero; Vector2 end_pos = Vector2.Zero; SortedSet <float> keys = new SortedSet <float>(ray_rads_and_lengths.Keys); for (int i = 0; i < 60; i++) { float curr_rad = RayPainter.GetRadianAt(i % 60); float next_rad = RayPainter.GetRadianAt((i + 1) % 60); beg_pos = tile_origin + (Vector2.UnitX.RotatedBy(curr_rad) * ray_rads_and_lengths[curr_rad]); end_pos = tile_origin + (Vector2.UnitX.RotatedBy(next_rad) * ray_rads_and_lengths[next_rad]); double add_rad = Math.Atan2(end_pos.Y - beg_pos.Y, end_pos.X - beg_pos.X); end_pos += Vector2.UnitX.RotatedBy(add_rad) * 2f; colorer.ColorTileLine(mymod, (int)beg_pos.X, (int)beg_pos.Y, (int)end_pos.X, (int)end_pos.Y); //ErrorLogger.Log( "PaintRadiationEdges x:"+tile_x+", y:"+tile_y+", rad:"+rad+", len:"+ray_rads_and_lengths[rad]+", offset:"+curr_tile_offset.ToString()); } }
void OkClick(object sender, RoutedEventArgs e) { result = new Result { XExpression = XExpression, YExpression = YExpression, WidthExpression = WidthExpression, HeightExpression = HeightExpression, FillColor = Colorer.StringToString(FillColor) }; xExpression.AddCurrentSuggestion(); yExpression.AddCurrentSuggestion(); widthExpression.AddCurrentSuggestion(); heightExpression.AddCurrentSuggestion(); aspectRatio.AddCurrentSuggestion(); fillColor.AddCurrentSuggestion(); DialogResult = true; }
public void ColorerTest() { // StringToString Assert.AreEqual(Colorer.StringToString("a"), "ffaaaaaa"); Assert.AreEqual(Colorer.StringToString("AB"), "ffababab"); Assert.AreEqual(Colorer.StringToString("cD0"), "ffccdd00"); Assert.AreEqual(Colorer.StringToString("C0DE"), "cc00ddee"); try { Colorer.StringToString("ad0be"); Assert.Fail(); } catch { } Assert.AreEqual(Colorer.StringToString("dEc0dE"), "ffdec0de"); try { Colorer.StringToString("dec0ded"); Assert.Fail(); } catch { } Assert.AreEqual(Colorer.StringToString("F00dFaCe"), "f00dface"); try { Colorer.StringToString("coder"); Assert.Fail(); } catch { } try { Colorer.StringToString("deadbeeff00d"); Assert.Fail(); } catch { } // StringToValue Assert.AreEqual(Colorer.StringToValue("a"), 0xffaaaaaa); Assert.AreEqual(Colorer.StringToValue("AB"), 0xffababab); Assert.AreEqual(Colorer.StringToValue("cD0"), 0xffccdd00); Assert.AreEqual(Colorer.StringToValue("C0DE"), 0xcc00ddee); try { Colorer.StringToValue("ad0be"); Assert.Fail(); } catch { } Assert.AreEqual(Colorer.StringToValue("dEc0dE"), 0xffdec0de); try { Colorer.StringToValue("dec0ded"); Assert.Fail(); } catch { } Assert.AreEqual(Colorer.StringToValue("F00dFaCe"), 0xf00dface); try { Colorer.StringToValue("coder"); Assert.Fail(); } catch { } try { Colorer.StringToValue("deadbeeff00d"); Assert.Fail(); } catch { } // ValueToString Assert.AreEqual(Colorer.ValueToString(0xffaaaaaa), "ffaaaaaa"); Assert.AreEqual(Colorer.ValueToString(0xffababab), "ffababab"); Assert.AreEqual(Colorer.ValueToString(0xffccdd00), "ffccdd00"); Assert.AreEqual(Colorer.ValueToString(0xcc00ddee), "cc00ddee"); Assert.AreEqual(Colorer.ValueToString(0xffdec0de), "ffdec0de"); Assert.AreEqual(Colorer.ValueToString(0xf00dface), "f00dface"); // ValueToARGB ValueToARGB(0xffaaaaaa, 0xff, 0xaa, 0xaa, 0xaa); ValueToARGB(0xffababab, 0xff, 0xab, 0xab, 0xab); ValueToARGB(0xffccdd00, 0xff, 0xcc, 0xdd, 0x00); ValueToARGB(0xcc00ddee, 0xcc, 0x00, 0xdd, 0xee); ValueToARGB(0xffdec0de, 0xff, 0xde, 0xc0, 0xde); ValueToARGB(0xf00dface, 0xf0, 0x0d, 0xfa, 0xce); // StringToARGB StringToARGB("a", 0xff, 0xaa, 0xaa, 0xaa); StringToARGB("AB", 0xff, 0xab, 0xab, 0xab); StringToARGB("cD0", 0xff, 0xcc, 0xdd, 0x00); StringToARGB("C0DE", 0xcc, 0x00, 0xdd, 0xee); try { StringToARGB("ad0be", 0, 0, 0, 0); Assert.Fail(); } catch { } StringToARGB("dEc0dE", 0xff, 0xde, 0xc0, 0xde); try { StringToARGB("dec0ded", 0, 0, 0, 0); Assert.Fail(); } catch { } StringToARGB("F00dFaCe", 0xf0, 0x0d, 0xfa, 0xce); try { StringToARGB("coder", 0, 0, 0, 0); Assert.Fail(); } catch { } try { StringToARGB("deadbeeff00d", 0, 0, 0, 0); Assert.Fail(); } catch { } // ARGBToString Assert.AreEqual(Colorer.ARGBToString(0xff, 0xaa, 0xaa, 0xaa), "ffaaaaaa"); Assert.AreEqual(Colorer.ARGBToString(0xff, 0xab, 0xab, 0xab), "ffababab"); Assert.AreEqual(Colorer.ARGBToString(0xff, 0xcc, 0xdd, 0x00), "ffccdd00"); Assert.AreEqual(Colorer.ARGBToString(0xcc, 0x00, 0xdd, 0xee), "cc00ddee"); Assert.AreEqual(Colorer.ARGBToString(0xff, 0xde, 0xc0, 0xde), "ffdec0de"); Assert.AreEqual(Colorer.ARGBToString(0xf0, 0x0d, 0xfa, 0xce), "f00dface"); // ARGBToValue Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xaa, 0xaa, 0xaa), 0xffaaaaaa); Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xab, 0xab, 0xab), 0xffababab); Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xcc, 0xdd, 0x00), 0xffccdd00); Assert.AreEqual(Colorer.ARGBToValue(0xcc, 0x00, 0xdd, 0xee), 0xcc00ddee); Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xde, 0xc0, 0xde), 0xffdec0de); Assert.AreEqual(Colorer.ARGBToValue(0xf0, 0x0d, 0xfa, 0xce), 0xf00dface); }
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { Colorer.StringToARGB(value as string, out byte alpha, out byte red, out byte green, out byte blue); return(new object[] { alpha, red, green, blue }); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => Colorer.ARGBToString((byte)values[0], (byte)values[1], (byte)values[2], (byte)values[3]);
void Command_Image_Crop(ImageCropDialog.Result result) { var variables = GetVariables(); var destX = new NEExpression(result.XExpression).Evaluate <int>(variables); var destY = new NEExpression(result.YExpression).Evaluate <int>(variables); var newWidth = new NEExpression(result.WidthExpression).Evaluate <int>(variables); var newHeight = new NEExpression(result.HeightExpression).Evaluate <int>(variables); if ((newWidth <= 0) || (newHeight <= 0)) { throw new Exception("Width and height must be greater than 0"); } var bitmap = GetBitmap(); var srcX = 0; var srcY = 0; var width = bitmap.Width; var height = bitmap.Height; if (destX < 0) { width += destX; srcX -= destX; destX = 0; } if (destY < 0) { height += destY; srcY -= destY; destY = 0; } width = Math.Min(width, newWidth - destX); height = Math.Min(height, newHeight - destY); var resultBitmap = new System.Drawing.Bitmap(newWidth, newHeight, bitmap.PixelFormat); resultBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution); using (var graphics = System.Drawing.Graphics.FromImage(resultBitmap)) using (var wrapMode = new System.Drawing.Imaging.ImageAttributes()) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb((int)Colorer.StringToValue(result.FillColor))), new System.Drawing.Rectangle(System.Drawing.Point.Empty, resultBitmap.Size)); graphics.DrawImage(bitmap, new System.Drawing.Rectangle(destX, destY, width, height), new System.Drawing.Rectangle(srcX, srcY, width, height), System.Drawing.GraphicsUnit.Pixel); } Replace(new List <Range> { FullRange }, new List <string> { Coder.BitmapToString(resultBitmap) }); SetSelections(new List <Range> { BeginRange }); }