示例#1
0
        internal Bitmap DrawSnapshot(int[] intensities)
        {
            Bitmap bitmap = new Bitmap(Resolution, Resolution);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.Clear(Color.DarkBlue);

                for (int i = 0; i < shapes.Count; i++)
                {
                    EyeWebShape shape = shapes[i];
                    int         tint  = intensities[i];
                    if (tint < 0)
                    {
                        tint = 0;
                    }
                    if (tint > 255)
                    {
                        tint = 255;
                    }

                    using (Brush brush = new SolidBrush(Color.FromArgb(tint, tint, tint)))
                        graphics.FillPolygon(brush, shape.targetPoints);
                }
            }
            return(bitmap);
        }
示例#2
0
        public EyeWeb(int subsectionsPerTone = 1, float powerBase = 1.8f, float centerSubstract = 0.5f, int resolution = 512)
        {
            this.Resolution = resolution;
            double toneWidth = 1.0 / subsectionsPerTone;

            for (int i = 0; i < 84; i++)
            {
                for (int j = 0; j < subsectionsPerTone; j++)
                {
                    EyeWebShape shape = new EyeWebShape(i + j * toneWidth, toneWidth, powerBase, centerSubstract);

                    shapes.Add(shape);
                    foreach (EyeWebCoordinate coordinate in shape.coordinates)
                    {
                        if (Math.Abs(coordinate.x) > extent)
                        {
                            extent = Math.Abs(coordinate.x);
                        }
                        if (Math.Abs(coordinate.y) > extent)
                        {
                            extent = Math.Abs(coordinate.y);
                        }
                    }
                }
            }
            foreach (EyeWebShape shape in shapes)
            {
                shape.BuildTargetPoints(extent, Resolution);
            }


            //Generating PointShapeIndex.
            int squareSize = resolution * resolution;

            PointShapeIndex = new int[squareSize];
            for (int i = 0; i < squareSize; i++)
            {
                PointShapeIndex[i] = -1;
            }

            PointShapeIndexCounter = new int[shapes.Count];

            int halfResolution = resolution / 2;

            List <Polygon> polygons = new List <Polygon>();

            for (int i = 0; i < shapes.Count; i++)
            {
                polygons.Add(new Polygon(GetPoints(i, resolution, halfResolution, halfResolution)));
            }

            for (int y = 0; y < resolution; y++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    for (int shapeIndex = shapes.Count - 1; shapeIndex >= 0; shapeIndex--)
                    {
                        if (polygons[shapeIndex].IsInside(x, y))
                        {
                            int index = y * resolution + x;
                            PointShapeIndex[index] = shapeIndex;
                            PointShapeIndexCounter[shapeIndex]++;
                            break;
                        }
                    }
                }
            }
        }