public void DrawPolygon(Polygon polygon, Color3Ch color, int lineThickness) { if (polygon == null || polygon.PointsCount == 0) { return; } var points = polygon.Points.ToPoints2D(); var max = polygon.PointsCount - 1; for (int i = 0; i < max; ++i) { var pt1 = points[i]; var pt2 = points[i + 1]; DrawLine(pt1, pt2, color, lineThickness); } if (max > 0) { DrawLine(points[max], points[0], color, lineThickness); } else { DrawLine(points[0], new Point2D(points[0].X + 1, points[0].Y), color, lineThickness); } }
public void DrawRectangle(Point2D leftTop, Point2D rightBottom, Color3Ch color) { Change(leftTop.X, leftTop.Y); Change(rightBottom.X, rightBottom.Y); for (int x = leftTop.X; x <= rightBottom.X; x++) { for (int y = leftTop.Y; y <= rightBottom.Y; y++) { R[x][y] = color.Red; G[x][y] = color.Green; B[x][y] = color.Blue; } } }
public void Fill(Color3Ch color) { //DrawRectangle(Point2D.Zero, new Point2D(width - 1, height - 1), color); Change(0, 0); Change(width - 1, height - 1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { R[x][y] = color.Red; G[x][y] = color.Green; B[x][y] = color.Blue; } } }
public void Fill(Point2D from, Color3Ch color) { throw new NotImplementedException("use polygon with scan-line fill"); }
public void DrawLine(Point2D start, Point2D end, Color3Ch color, int thickness = 1) { DrawLine(start.X, start.Y, end.X, end.Y, color.Red, color.Green, color.Blue, thickness); }
public void SetPixelBatch(int x, int y, Color3Ch color) { SetPixelBatch(x, y, color.Red, color.Green, color.Blue); }
public void FillPolygon(Polygon polygon, Color3Ch color) { if (polygon == null || polygon.PointsCount == 0) { return; } var points = polygon.Points.ToPoints2D(); var max = polygon.PointsCount - 1; int minx; int maxx; IList <Tuple <Point2D, Point2D> > edges = PointsToEdges(points, out minx, out maxx); Change(Math.Max(minx, 0), Math.Max(edges[0].Item1.Y, 0)); Change(Math.Min(maxx, width - 1), Math.Min(edges[max].Item2.Y, height - 1)); bool[] active; double[] ratios; double[] xs; InitializeClipSupport(edges, out active, out ratios, out xs); int minActive = edges.Count; int maxActive = 0; for (int y = Math.Max(edges[0].Item1.Y, 0); y < height; ++y) { bool noneActive = true; for (int i = 0; i < edges.Count; ++i) { // modify coordinates of active x coordinates if (active[i]) { xs[i] += ratios[i]; } // activate/deactivate edges active[i] = y >= edges[i].Item1.Y && y < edges[i].Item2.Y; if (!active[i]) { continue; } // change active indices range noneActive = false; if (i < minActive) { minActive = i; } if (i > maxActive) { maxActive = i; } } if (noneActive) { break; } // compose a list of x coordinates of current borders List <int> xx = new List <int>(); for (int i = minActive; i <= maxActive; ++i) { if (active[i]) { int j; for (j = 0; j < xx.Count; ++j) { if (xx[j] >= xs[i]) { break; } } xx.Insert(j, Math.Max((int)Math.Round(xs[i]), 0)); } } #region draw row if (xx[0] < width) { bool isDrawing = true; int xchecked = 1; if ((xx.Count == 1 && xx[0] > 0) || (xx.Count > 1 && xx[1] > 0)) { R[xx[0]][y] = color.Red; G[xx[0]][y] = color.Green; B[xx[0]][y] = color.Blue; } for (int x = xx[0] + 1; x < width; ++x) { if (x >= xx[xchecked]) { ++xchecked; isDrawing = !isDrawing; } if (isDrawing) { R[x][y] = color.Red; G[x][y] = color.Green; B[x][y] = color.Blue; } else { if (xchecked == xx.Count) { break; } x = xx[xchecked] - 1; } } } #endregion } }