Example #1
0
        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;
        }
Example #2
0
 public static void FakeDrawPixel(this IPixelDrawable target, IEnumerable <KeyValuePair <Point, Color> > points)
 {
     if (target != null && points != null && target.IsReady)
     {
         foreach (var obj in points)
         {
             target.FakeDrawPixel(obj.Key, obj.Value);
         }
     }
 }
Example #3
0
        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;
        }
Example #4
0
        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);
        }
Example #5
0
 public static IEnumerable<KeyValuePair<Point, Color>> GetPointsWithSameColor(IPixelDrawable d, Point begin, Color c)
 {
     Dictionary<Point, Color> visited = new Dictionary<Point, Color>();
     SearchPointsWithColor(d, begin, c, visited);
     return visited;
 }
Example #6
0
        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);
        }
Example #7
0
        public static IEnumerable <KeyValuePair <Point, Color> > GetPointsWithSameColor(IPixelDrawable d, Point begin, Color c)
        {
            Dictionary <Point, Color> visited = new Dictionary <Point, Color>();

            SearchPointsWithColor(d, begin, c, visited);
            return(visited);
        }