/// <summary> /// Draws Koch Curve /// </summary> /// <param name="flag">refresh image in imageBox</param> private void DrowKochCurve(bool flag = true) { Console.WriteLine("Redraw"); Console.WriteLine("Size is "); Console.WriteLine(picCanvas.Width + " " + picCanvas.Height); Console.WriteLine(this.Width.ToString() + " " + this.Height.ToString()); //mBm = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); double width = this.picCanvas.Width; double height = this.picCanvas.Height; double len = Math.Min((height - 20) * 2 / Math.Sqrt(3), (width - 20) / 3); Console.WriteLine($"Len is {len}"); lastImage = new Bitmap((int)(width * Fractal.imageQualityFactor), (int)(height * Fractal.imageQualityFactor)); Point startPoint = new Point((width - 3 * len) / 2, height / 2 + len / 4 * Math.Sqrt(3)); Point endPoint = new Point(width - (width - 3 * len) / 2, startPoint.Y); Console.WriteLine(startPoint); Console.WriteLine(endPoint); KochCurve curve = new KochCurve(0, startColor, endColor, (int)iterationsUpDown.Value); curve.Draw(lastImage, startPoint, endPoint); if (flag) { (picCanvas.Image)?.Dispose(); picCanvas.Image = lastImage; } }
/// <summary> /// Draws Koch Curve fractal /// </summary> /// <param name="image"></param> /// <param name="A"></param> /// <param name="E"></param> /// <param name="helper"></param> public override void Draw(Bitmap image, Point A, Point E, int helper = 0) { /* C * A__B/\D__E */ if (CurDepth == MaxDepth) { Pen gradientPen = new Pen(Fractal.GetGradientColor(StartColor, EndColor, helper, MaxDepth), (float)(startThickness)); using (var graphics = Graphics.FromImage(image)) { var offA = (A - offsetPoint) * imageQualityFactor; var offE = (E - offsetPoint) * imageQualityFactor; graphics.DrawLine(gradientPen, (float)offA.X, (float)offA.Y, (float)offE.X, (float)offE.Y); } } else { Point B = A + (E - A) / 3; Point D = A + (E - A) * (2.0 / 3); Point temp = D - B; temp = Point.Rotate(temp, -Math.PI / 3); Point C = B + temp; Point[] arr = new Point[5] { A, B, C, D, E }; for (int i = 0; i < 4; ++i) { var newFractal = new KochCurve(StartLen, StartColor, EndColor, MaxDepth, CurDepth + 1); int newHelper = helper; if (i == 1 || i == 2) { newHelper++; } newFractal.Draw(image, arr[i], arr[i + 1], newHelper); } } }