예제 #1
0
        /// <summary>
        /// Draws H-Fractal
        /// </summary>
        /// <param name="flag">refresh image on PictureBox?</param>
        private void DrawHFractal(bool flag = true)
        {
            Console.WriteLine("H-fractal");
            double width  = this.picCanvas.Width;
            double height = this.picCanvas.Height;

            double maxLen = (double)Math.Min(picCanvas.Width, picCanvas.Height) / 2.1;

            Console.WriteLine($"MaxLen is {maxLen}");

            Point midPoint = new Point(width / 2, height / 2);

            lastImage = new Bitmap((int)(width * Fractal.imageQualityFactor), (int)(height * Fractal.imageQualityFactor));

            Console.WriteLine("MidPoint " + midPoint);

            HFractal fractal = new HFractal(maxLen, startColor, endColor, (int)iterationsUpDown.Value);

            fractal.Draw(lastImage, midPoint);
            if (flag)
            {
                (picCanvas.Image)?.Dispose();
                picCanvas.Image = lastImage;
            }
        }
예제 #2
0
        /// <summary>
        /// method for drawing H-Fractal on image
        /// </summary>
        /// <param name="image">image to draw on</param>
        /// <param name="A">leftmost Point</param>
        /// <param name="E">rightmost Point</param>
        public override void Draw(Bitmap image, Point pt1, Point pt2 = null, int helper = 0)
        {
            if (MaxDepth == CurDepth)
            {
                return;
            }
            double curLen = StartLen / (Math.Pow(2, CurDepth));

            /*
             *
             * C |    |D
             * A|____|B
             *  |    |
             * E |    |F
             */
            //pt1 -= offsetPoint;

            Point A = new Point(pt1.X - curLen / 2, pt1.Y);
            Point B = new Point(pt1.X + curLen / 2, pt1.Y);
            Point C = new Point(A.X, A.Y + curLen / 2);

            Point D = new Point(B.X, B.Y + curLen / 2);

            Point E = new Point(A.X, A.Y - curLen / 2);

            Point F = new Point(B.X, B.Y - curLen / 2);


            Pen GradientPen = new Pen(Fractal.GetGradientColor(StartColor, EndColor, CurDepth, MaxDepth), (startThickness));

            using (var graphics = Graphics.FromImage(image))
            {
                var offA = (A - offsetPoint) * imageQualityFactor;
                var offB = (B - offsetPoint) * imageQualityFactor;
                var offC = (C - offsetPoint) * imageQualityFactor;
                var offD = (D - offsetPoint) * imageQualityFactor;
                var offF = (F - offsetPoint) * imageQualityFactor;
                var offE = (E - offsetPoint) * imageQualityFactor;


                graphics.DrawLine(GradientPen, (float)offA.X, (float)offA.Y, (float)offE.X, (float)offE.Y);
                graphics.DrawLine(GradientPen, (float)offA.X, (float)offA.Y, (float)offC.X, (float)offC.Y);
                graphics.DrawLine(GradientPen, (float)offA.X, (float)offA.Y, (float)offB.X, (float)offB.Y);
                graphics.DrawLine(GradientPen, (float)offB.X, (float)offB.Y, (float)offF.X, (float)offF.Y);
                graphics.DrawLine(GradientPen, (float)offB.X, (float)offB.Y, (float)offD.X, (float)offD.Y);
            }

            Point[] arr = { C, E, D, F };
            for (int i = 0; i < arr.Length; ++i)
            {
                HFractal nextStepFractal = new HFractal(StartLen, StartColor, EndColor, MaxDepth, CurDepth + 1);
                nextStepFractal.Draw(image, arr[i]);
            }
        }