public static IEnumerable <KeyValuePair <Point, Color> > GetDistributionColor(this IEnumerable <KeyValuePair <Point, Color> > points, IPixelDrawable d, int width) { Dictionary <Point, Color> result = new Dictionary <Point, Color>(); foreach (var obj in points) { if (obj.Key.X >= 0 && obj.Key.X <= d.PixelSize.Width && obj.Key.Y >= 0 && obj.Key.Y <= d.PixelSize.Height) { int l = (int)Math.Ceiling((width - 1) / 2.0); for (int i = obj.Key.X - l; i <= obj.Key.X + l; ++i) { for (int j = obj.Key.Y - l; j <= obj.Key.Y + l; ++j) { var p = new Point(i, j); var old_c = d.ReadPixel(p); if (result.ContainsKey(p)) { old_c = result[p]; } result[p] = CozyPixelHelper.Blend(obj.Value, old_c, CozyPixelHelper.LinearWeight(obj.Key.Length(p), width));; } } } } return(result); }
public static IEnumerable<KeyValuePair<Point, Color>> GetDistributionColor(this IEnumerable<KeyValuePair<Point, Color>> points, IPixelDrawable d, int width) { Dictionary<Point, Color> result = new Dictionary<Point, Color>(); foreach(var obj in points) { if(obj.Key.X >= 0 && obj.Key.X <= d.PixelSize.Width && obj.Key.Y >= 0 && obj.Key.Y <= d.PixelSize.Height) { int l = (int)Math.Ceiling((width - 1) / 2.0); for(int i = obj.Key.X - l; i <= obj.Key.X + l; ++i) { for (int j = obj.Key.Y - l; j <= obj.Key.Y + l; ++j) { var p = new Point(i, j); var old_c = d.ReadPixel(p); if (result.ContainsKey(p)) { old_c = result[p]; } result[p] = CozyPixelHelper.Blend(obj.Value, old_c, CozyPixelHelper.LinearWeight(obj.Key.Length(p), width)); ; } } } } return result; }
private static int SearchPointsWithColor(IPixelDrawable d, Point p, Color c, Dictionary<Point, Color> visited) { if (p.X < 0 || p.Y < 0 || p.X >= d.PixelSize.Width || p.Y >= d.PixelSize.Height || d.ReadPixel(p) != c) { return 0; } if (visited.ContainsKey(p)) { return 0; } int count = 1; visited[p] = c; count += SearchPointsWithColor(d, new Point(p.X, p.Y + 1), c, visited); count += SearchPointsWithColor(d, new Point(p.X, p.Y - 1), c, visited); count += SearchPointsWithColor(d, new Point(p.X + 1, p.Y), c, visited); count += SearchPointsWithColor(d, new Point(p.X - 1, p.Y), c, visited); return count; }
private static int SearchPointsWithColor(IPixelDrawable d, Point p, Color c, Dictionary <Point, Color> visited) { if (p.X < 0 || p.Y < 0 || p.X >= d.PixelSize.Width || p.Y >= d.PixelSize.Height || d.ReadPixel(p) != c) { return(0); } if (visited.ContainsKey(p)) { return(0); } int count = 1; visited[p] = c; count += SearchPointsWithColor(d, new Point(p.X, p.Y + 1), c, visited); count += SearchPointsWithColor(d, new Point(p.X, p.Y - 1), c, visited); count += SearchPointsWithColor(d, new Point(p.X + 1, p.Y), c, visited); count += SearchPointsWithColor(d, new Point(p.X - 1, p.Y), c, visited); return(count); }