private ICustomPoint[] InitStartCoordinates() { ICustomPoint[] coords = new ICustomPoint[3]; coords.SetValue(new CPoint(300, 0), 0); coords.SetValue(new CPoint(0, 600), 1); coords.SetValue(new CPoint(600, 600), 2); return(coords); }
private void Draw(ICustomPoint[] coordinates, int level) { if (level == 0) { DrawTriangle(coordinates); return; } level--; ICustomPoint[,] innerTrianglesCoords = CalculateInnerTrianglesCoordinates(coordinates, _scale); for (var i = 0; i < 3; i++) { ICustomPoint[] innerTriangleCoords = new ICustomPoint[3]; for (var j = 0; j < 3; j++) { innerTriangleCoords.SetValue(innerTrianglesCoords[i, j], j); } Draw(innerTriangleCoords, level); } }
private ICustomPoint[,] CalculateInnerTrianglesCoordinates(ICustomPoint[] outerTriangleCoords, double scale) { ICustomPoint[,] newCoords = new ICustomPoint[outerTriangleCoords.Length, outerTriangleCoords.Length]; for (var i = 0; i < outerTriangleCoords.Length; i += 1) { ICustomPoint current = outerTriangleCoords[i]; ICustomPoint next = null; ICustomPoint prev = null; newCoords.SetValue(current, i, 0); if (i == 0) { next = outerTriangleCoords[i + 1]; prev = outerTriangleCoords[i + 2]; } else if (i == outerTriangleCoords.Length - 1) { next = outerTriangleCoords[i - 1]; prev = outerTriangleCoords[i - 2]; } else { next = outerTriangleCoords[i + 1]; prev = outerTriangleCoords[i - 1]; } ICustomPoint nextPointCoords = current.GetPointOnLine(next, scale); ICustomPoint prevPointCoords = current.GetPointOnLine(prev, scale); newCoords.SetValue(nextPointCoords, i, 1); newCoords.SetValue(prevPointCoords, i, 2); } return(newCoords); }
private void _calculateNewCoordinates() { var newPoints = new ICustomPoint[4]; for (int counter = 0; counter < _points.Length; counter++) { var currentPoint = _points[counter]; var nextPoint = counter == _points.Length - 1 ? _points[0] : _points[counter + 1]; var newPoint = currentPoint.GetPointOnLine(nextPoint, _scale); newPoints.SetValue(newPoint, counter); } _points = newPoints; }