Пример #1
0
        private void BlitFadedCircle(Rect r, float val)
        {
            r.halfHeight = r.halfWidth;
            Point min = new Point {
                x = r.centreX - r.halfWidth, y = r.centreY - r.halfHeight
            };
            Point max = new Point {
                x = r.centreX + r.halfWidth, y = r.centreY + r.halfHeight
            };
            float maxDistSqr = r.halfWidth * r.halfWidth;

            for (int y = min.y; y < max.y; ++y)
            {
                for (int x = min.x; x < max.x; ++x)
                {
                    if (!GridUtilities.IsGridPosSafe(x, y, _width, _height))
                    {
                        continue;
                    }
                    float distSqr = GridUtilities.DistanceSqr(r.centreX, r.centreY, x, y);
                    float scale   = 1 - (distSqr / maxDistSqr);
                    if (scale < 0)
                    {
                        continue;
                    }
                    float addition = val * scale;
                    _map[GridUtilities.GridPosToIndex(x, y, _width)] += addition;
                }
            }
        }
Пример #2
0
        public int QueueQueryForBestZero(int originX, int originY)
        {
            Point best = new Point {
                x = originX, y = originY
            };
            float bestDistSqr = 9999;

            for (int y = 0; y < _height; ++y)
            {
                for (int x = 0; x < _width; ++x)
                {
                    if (x == originX && y == originY)
                    {
                        continue;
                    }
                    float queryDistSqr = GridUtilities.DistanceSqr(originX, originY, x, y);
                    if (queryDistSqr < bestDistSqr)
                    {
                        best.x      = x;
                        best.y      = y;
                        bestDistSqr = queryDistSqr;
                    }
                }
            }
            QueueSetPixel(best.x, best.y, 5.55f);
            return(0);
        }