예제 #1
0
        public static ColorPolygon GeneratePolygon(int x, int y, int width, int height)
        {
            var randomPoints = new List<Point>();
            for (var i = 0; i < 10; i++) randomPoints.Add(new Point(x + Random.Next(width), y + Random.Next(height)));

            var hull = ConvexHull(randomPoints.ToArray());
            hull.Reverse();

            var filling = ScanLine.PolygonFilling(hull.Select(p => new Point(p.X - x, p.Y - y)).ToList(),out var colorTab,true,width,height);
            var polygon = new ColorPolygon(hull, Color.Black, colorTab,filling);
            polygon.Shift.Y = y;
            return polygon;
        }
예제 #2
0
 public ClippedPolygon(List <Point> points, ColorPolygon colorPoly)
 {
     Points    = points;
     ColorPoly = colorPoly;
 }
예제 #3
0
        public void DrawPoints(List <Point> points, Color color, bool inside = false, ColorPolygon colorPolygon = null)
        {
            for (var i = 0; i < points.Count; i++)
            {
                var point = points[i];
                var x     = point.X;
                var y     = point.Y;

                if (x < 0 || x >= _width || y < 0 || y >= _height)
                {
                    continue;
                }

                if (inside)
                {
                    color = MainTexture.texture[x, y];
                    double dot = dotProducts[x, y];

                    var R = ((color.R / 255d) + (_lightColor.R / 255d)) / 2 * dot;
                    var G = ((color.G / 255d) + (_lightColor.G / 255d)) / 2 * dot;
                    var B = ((color.B / 255d) + (_lightColor.B / 255d)) / 2 * dot;
                    R     = Math.Min(Math.Max(0, R), 1);
                    G     = Math.Min(Math.Max(0, G), 1);
                    B     = Math.Min(Math.Max(0, B), 1);
                    color = Color.FromArgb((int)(255 * R), (int)(255 * G), (int)(255 * B));
                }

                if (colorPolygon != null)
                {
                    if (color != Color.White)
                    {
                        color = colorPolygon.ColorTab[x, y];
                    }

                    x += colorPolygon.Shift.X;
                    y += colorPolygon.Shift.Y;

                    if (x >= _width || y >= _height)
                    {
                        continue;
                    }
                }

                var pixelOffset = CalculatePixelOffset(x, y);
                _sourceBuffer[pixelOffset]     = color.B;
                _sourceBuffer[pixelOffset + 1] = color.G;
                _sourceBuffer[pixelOffset + 2] = color.R;
                _sourceBuffer[pixelOffset + 3] = color.A;
            }
        }