/// <summary> /// Рисование кривой Коха. /// </summary> /// <param name="target"> Где рисовать.</param> private void KohLine(Graphics target) { SetupForElse(); Point start = new Point(pictureBox.Location.X + 100, pictureBox.Location.Y + pictureBox.Size.Height / 2); Point end = new Point(pictureBox.Location.X + pictureBox.Size.Width - 100, pictureBox.Location.Y + pictureBox.Size.Height / 2); Point middle = new Point((start.X + end.X) / 2, (start.Y + end.Y) / 2); start = new Point((start.X - middle.X) * delta + middle.X, (start.Y - middle.Y) * delta + middle.Y); start.X += current.X; start.Y += current.Y; end = new Point((end.X - middle.X) * delta + middle.X, (end.Y - middle.Y) * delta + middle.Y); end.X += current.X; end.Y += current.Y; Koh fractKoh = new Koh(start, end); fractKoh.Refresh(recur, target); }
/// <summary> /// Функция для отрисовки прямой. /// </summary> /// <param name="depth"> Глубина рекурсии.</param> /// <param name="target"> Где рисовать.</param> public override void Refresh(int depth, Graphics target) { Draw(target, this); if (depth <= maxRecur) { if (depth > 0) { // Считаем вершину треугольника, закрашиваем центр и рекурсино вызываем от двух каждых соседних вершин. Point firstThird = new Point((2 * start.X + end.X) / 3, (2 * start.Y + end.Y) / 3); Point secondThird = new Point((start.X + 2 * end.X) / 3, (start.Y + 2 * end.Y) / 3); target.DrawLine(new Pen(Color.White, 4), firstThird, secondThird); Point newDot = new Point(Convert.ToInt32((secondThird.X - firstThird.X) * Math.Cos(-Math.PI / 3) - (secondThird.Y - firstThird.Y) * Math.Sin(-Math.PI / 3) + firstThird.X), Convert.ToInt32((secondThird.X - firstThird.X) * Math.Sin(-Math.PI / 3) + (secondThird.Y - firstThird.Y) * Math.Cos(-Math.PI / 3) + firstThird.Y)); var first = new Koh(start, firstThird); var second = new Koh(firstThird, newDot); var third = new Koh(newDot, secondThird); var fourth = new Koh(secondThird, end); first.Refresh(depth - 1, target); second.Refresh(depth - 1, target); third.Refresh(depth - 1, target); fourth.Refresh(depth - 1, target); } } }