Exemplo n.º 1
0
        private void DrawLineFlags(Raster raster, int x0, int y0, int x1, int y1)
        {
            if (y0 > y1)
            {
                Swap(ref x0, ref x1);
                Swap(ref y0, ref y1);
            }

            int deltax = x1 - x0;
            int deltay = y1 - y0;

            if (deltay == 0)
            {
                //raster.SetPixel(x0, y0, 255);
                //raster.SetPixel(x1, y1, 255);
                return;
            }

            float error      = 0;
            float deltaError = (float)deltax / (float)deltay;

            int x = x0;

            for (int y = y0; y < y1; y++)
            {
                raster.AddPixel(x, y, 1);
                error += deltaError;
                if (error > 0.5)
                {
                    x++;
                    error -= 1.0f;
                }
                if (error < 0.5)
                {
                    x--;
                    error += 1.0f;
                }
            }
        }