Esempio n. 1
0
        static public void Fill(Polygon poly, Bitmap canvas, IFillModule fillModule)
        {
            var(edgeTable, numOfScanLines, y0) = CreateEdgeTable(poly);
            var activeEdgeList = new List <EdgeBucket>();

            for (int i = 0; i < numOfScanLines; i++)
            {
                var y = i + y0;

                activeEdgeList.RemoveAll(e => e.ymax <= y);


                if (edgeTable[i].list != null)
                {
                    foreach (var e in edgeTable[i].list)
                    {
                        activeEdgeList.Add(e);
                    }
                }

                activeEdgeList.Sort((a, b) => a.x.CompareTo(b.x));

                var even      = activeEdgeList.Where((x, k) => k % 2 == 0);
                var odd       = activeEdgeList.Where((x, k) => k % 2 == 1);
                var edgePairs = even.Zip(odd, (first, second) => (first, second));
                foreach (var pair in edgePairs)
                {
                    for (int x = pair.first.x; x <= pair.second.x; x++)
                    {
                        canvas.SetPixel(x, y, fillModule.GetColor(x, y));
                    }
                }

                for (int k = 0; k < activeEdgeList.Count; k++)
                {
                    var edge = activeEdgeList.ElementAt(k);
                    activeEdgeList.RemoveAt(k);

                    edge.exactx += edge.slopeinv;
                    edge.x       = (int)edge.exactx;

                    activeEdgeList.Insert(k, edge);
                }
            }
        }
 public AbstractLightFillModule(IFillModule baseModule, Color[][] normalMapColors, (int X, int Y) normalMax,
Esempio n. 3
0
 public LightColorFillModule(IFillModule baseModule, Color light)
 {
     _baseModule = baseModule;
     _light      = light;
 }