Exemplo n.º 1
0
        /// <summary>
        /// Draws Circle Fractal
        /// </summary>
        /// <param name="flag"> refresh image on pictureBox?</param>
        private void DrawCircleFractal(bool flag = true)
        {
            double width  = this.picCanvas.Width;
            double height = this.picCanvas.Height;

            double maxLen   = (double)Math.Min(picCanvas.Width, picCanvas.Height) / 2.1;
            Point  midPoint = new Point(width / 2, height / 2);

            lastImage = new Bitmap((int)(width * Fractal.imageQualityFactor), (int)(height * Fractal.imageQualityFactor));
            Console.WriteLine(iterationsUpDown.Value);
            CircleFractal fractal = new CircleFractal(maxLen, startColor, endColor, (int)iterationsUpDown.Value);

            fractal.Draw(lastImage, midPoint);
            if (flag)
            {
                (picCanvas.Image)?.Dispose();
                picCanvas.Image = lastImage;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// method for drawing Circle fractal on image
        /// </summary>
        /// <param name="image">image to draw on</param>
        /// <param name="A">center Point</param>
        /// <param name="E">null</param>
        public override void Draw(Bitmap image, Point pt1, Point pt2 = null, int helper = 0)
        {
            if (CurDepth == MaxDepth)
            {
                return;
            }

            Pen    gradientPen = new Pen(Fractal.GetGradientColor(StartColor, EndColor, CurDepth, MaxDepth), startThickness);
            double curRadius   = StartLen / (Math.Pow(3, CurDepth));

            Point[] arr = new Point[7];
            arr[0] = pt1;
            double distFromCenter = curRadius * 2 / 3;

            for (int i = -1; i < 6; ++i)
            {
                Point rotated = new Point(-distFromCenter, 0);
                rotated = Point.Rotate(rotated, Math.PI / 6 + Math.PI * i / 3);
                Point diag = new Point(-curRadius / 3 * Math.Sqrt(2), 0);
                diag       = Point.Rotate(diag, Math.PI / 4);
                arr[i + 1] = rotated + pt1;

                //drawing circle, that is in our center
                if (i == -1)
                {
                    arr[0] = pt1;
                }

                Point temp = arr[i + 1] + diag;


                using (var graphics = Graphics.FromImage(image))
                {
                    graphics.DrawEllipse(gradientPen,
                                         new RectangleF((float)(temp.X - offsetPoint.X) * imageQualityFactor, (float)(temp.Y - offsetPoint.Y) * imageQualityFactor, (float)curRadius / 3 * (float)2 * imageQualityFactor, (float)curRadius / 3 * (float)2 * imageQualityFactor));
                }

                CircleFractal fractal = new CircleFractal(StartLen, StartColor, EndColor, MaxDepth, CurDepth + 1);
                fractal.Draw(image, arr[i + 1]);
            }
        }