public MainWindow() { InitializeComponent(); SetupButtonTab(); _width = (int)PaintSurface.Width; _height = (int)PaintSurface.Height; _sourceRect = new Int32Rect(0, 0, _width, _height); SetupBitmap(); _sourceBuffer = new byte[_width * _height * (_wb.Format.BitsPerPixel / 8)]; ClearScreen(); Instance = this; RedrawAll(); var points1 = new System.Windows.Point[] { new System.Windows.Point(1, 1), new System.Windows.Point(1, 50), new System.Windows.Point(50, 1) }; var points2 = new System.Windows.Point[] { new System.Windows.Point(10, 10), new System.Windows.Point(10, 50), new System.Windows.Point(50, 10) }; var clip = SutherlandHodgman.GetIntersectedPolygon(points1, points2); List <Point> pointz = new List <Point>() { new Point(3, 0), new Point(0, 3), new Point(3, 6), new Point(6, 3) }; var filling = ScanLine.PolygonFilling(pointz, out var colorTab, true); UpdateDotProducts(); StartMainLoop(); }
private void CompositionTargetOnRendering(object sender, EventArgs e) { if (!_running) { return; } foreach (var colorPolygon in _generated) { colorPolygon.Clear(); colorPolygon.Vertices = colorPolygon.Vertices.Select(v => new Vertex(0, new Point(v.Point.X + _speed, v.Point.Y))).ToList(); // colorPolygon.ShiftInterior(_speed); colorPolygon.Shift.X += _speed; } if (_clearCounter++ % 60 == 0) { ClearGenerated(); } ClearClippedOnScreen(); _clipped.Clear(); foreach (var subject in _polygons) { foreach (var clip in _generated) { var temppoly = SutherlandHodgman.GetIntersectedPolygon( subject.Vertices.Select(p => new System.Windows.Point(p.Point.X, p.Point.Y)).ToArray(), clip.Vertices.Select(p => new System.Windows.Point(p.Point.X, p.Point.Y)).ToArray()); if (temppoly.Length != 0) { var poly = temppoly.Select(p => new Point((int)p.X, (int)p.Y)).ToList(); var filling = ScanLine.PolygonFilling(poly, out Color[,] xd); var polygon = new ClippedPolygon(filling, clip); _clipped.Add(polygon); } } } RedrawAll(); }
public MainWindow() { InitializeComponent(); _width = (int)PaintSurface.Width; _height = (int)PaintSurface.Height; _sourceRect = new Int32Rect(0, 0, _width, _height); SetupBitmap(); _sourceBuffer = new byte[_width * _height * (_wb.Format.BitsPerPixel / 8)]; ClearScreen(); Instance = this; var pointz = new List <Point> { new Point(3, 0), new Point(0, 3), new Point(3, 6), new Point(6, 3) }; var filling = ScanLine.PolygonFilling(pointz, out var colorTab, true); }
public void GeneratePolygons(float alpha) { DrawPoints(pointsToClear, Color.White); pointsToClear.Clear(); Matrix M1 = Matrix.ProjectionMatrix() * Matrix.ViewMatrix(alpha); Matrix M2 = M1 * Matrix.TranslationMatrix(new Vector3(0, 2, 0)); Matrix M3 = M1 * Matrix.TranslationMatrix(new Vector3(1, 1, 0)) * Matrix.RotateZMatrix((float)Math.PI / 2); var pointsToDraw = DrawTetragon(Vectors, M1); var filling1 = ScanLine.PolygonFilling(pointsToDraw, out Color[,] xd); DrawPoints(filling1, Color.Green); var pointsToDraw2 = DrawTetragon(Vectors, M3); var filling2 = ScanLine.PolygonFilling(pointsToDraw2, out Color[,] xd2); DrawPoints(filling2, Color.Yellow); pointsToClear.AddRange(filling1); pointsToClear.AddRange(filling2); // ClearScreen(); CommitDraw(); }
private void DrawPolygon(Point point) { if (!_started) { _started = true; _lastVertex = new Vertex(1, point); _newPolygon = new Polygon(Color.MidnightBlue); _newPolygon.Vertices.Add(_lastVertex); // DrawDot(point, Color.Crimson); CommitDraw(); return; } //Checking if it's time to end Cycle var firstVertex = _newPolygon.Vertices[0]; var length = point.Length(firstVertex.Point); Console.WriteLine(length); if (length < 15) { if (_newPolygon.Vertices.Count >= 3) { _started = false; var lastEdgePoints = GetLine(firstVertex.Point.X, firstVertex.Point.Y, _lastVertex.Point.X, _lastVertex.Point.Y); Edge lastEdge = new Edge(_lastVertex.Id, lastEdgePoints); _lastVertex.Edges[1] = firstVertex.Edges[0] = lastEdge; lastEdge.Vertices[0] = _lastVertex; lastEdge.Vertices[1] = firstVertex; _newPolygon.Edges.Add(lastEdge); var points = new List <Point>(); foreach (var edge in _newPolygon.Edges) { points.AddRange(edge.Points); } var colors = _mainTexture.GetAreaPixels(points); DrawPoints(points, Color.Black, colors); // DrawPoints(lastEdge.Points,Color.MidnightBlue); CommitDraw(); _polygonFilling = ScanLine.PolygonFilling(_newPolygon.Vertices.Select(v => v.Point).ToList(), out var colorTab); ExecuteFilter(); // RedrawImage(); } return; } //When it is time time to add not-start vertex var newVertex = new Vertex(_lastVertex.Id + 1, point); var edgePoints = GetLine(_lastVertex.Point.X, _lastVertex.Point.Y, point.X, point.Y); Edge newEdge = new Edge(_lastVertex.Id, edgePoints); _lastVertex.Edges[1] = newVertex.Edges[0] = newEdge; newEdge.Vertices[0] = _lastVertex; newEdge.Vertices[1] = newVertex; _newPolygon.Vertices.Add(newVertex); _newPolygon.Edges.Add(newEdge); //Drawing line and point // DrawDot(point, Color.Crimson); DrawPoints(newEdge.Points, Color.Red); CommitDraw(); _lastVertex = newVertex; }