示例#1
0
        public Color GetColor(int x, int y)
        {
            var baseColor = _baseModule.GetColor(x, y);
            var newRed    = (int)(baseColor.R * (double)_light.R / 255);
            var newGreen  = (int)(baseColor.G * (double)_light.G / 255);
            var newBlue   = (int)(baseColor.B * (double)_light.B / 255);
            var newColor  = Color.FromArgb(newRed, newGreen, newBlue);

            return(newColor);
        }
示例#2
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);
                }
            }
        }