public override void Render(IGraphics2DContext context)
        {
            int n;

            double w = context.Viewport.Width;
            double h = context.Viewport.Height;

            double step     = Math.Max(Region.Width / w, Region.Height / h);
            double offset_x = Region.X - (w * step - Region.Width) / 2.0;
            double offset_y = Region.Y - (h * step - Region.Height) / 2.0;

            CPolynomial p  = Polynomial;
            CPolynomial pd = Polynomial.FirstDerivative();

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    Complex Z     = new Complex(offset_x + x * step, offset_y + y * step);
                    Complex Delta = Z;
                    Complex Z1    = Z;

                    for (n = 0; (n < MaxIterations) && (Complex.Abs(Z) < BailOut) && Complex.Abs(Delta) > 1E-15; n++)
                    {
                        Z     = Z - p.Evaluate(Z) / pd.Evaluate(Z);
                        Delta = Z1 - Z;
                        Z1    = Z;
                    }

                    context.PutPixel(x, y, GetColor(Z, n, MaxIterations));
                }
            }
        }
Exemple #2
0
        private Rectangle RenderOrCalcMeasure(IGraphics2DContext context, double scale, bool render = true)
        {
            double x     = 0.0;
            double y     = 0.0;
            double max_x = 0;
            double max_y = 0;

            double mx = context.Viewport.Width / 2.0;
            double my = context.Viewport.Height / 2.0;

            for (int n = 0; n < Iterations; n++)
            {
                int signx = (x >= 0) ? 1 : -1;

                double t = x;
                x = y - signx * Math.Sqrt(Math.Abs(B * x - C));
                y = A - t;

                max_x = Math.Max(max_x, x);
                max_y = Math.Max(max_y, y);
                if (render)
                {
                    context.PutPixel(mx + x * scale, my - y * scale, Color);
                }
            }

            return(new Rectangle(-max_x, -max_y, 2 * max_x, 2 * max_y));
        }
Exemple #3
0
        public override void Render(IGraphics2DContext context)
        {
            Rectangle viewport = context.Viewport;
            double    side, h;

            if (viewport.Width > viewport.Height)
            {
                h    = viewport.Height;
                side = viewport.Height / (Math.Sqrt(3) / 2.0);
            }
            else
            {
                side = viewport.Width;
                h    = Math.Sqrt(3) / 2.0 * side;
            }

            double mx = viewport.X + viewport.Width / 2;
            double my = viewport.Y + viewport.Height / 2;

            Point p1 = new Point(mx, my - h / 2);
            Point p2 = new Point(mx + side / 2, my + h / 2);
            Point p3 = new Point(mx - side / 2, my + h / 2);

            Recursion(context, p1, p2, p3, Iterations);
        }
Exemple #4
0
        public override void Render(IGraphics2DContext context)
        {
            Rectangle viewport = context.Viewport;

            double x     = viewport.X;
            double y     = viewport.Y + viewport.Height / 2 - Iterations * LineHeight + LineHeight / 2;
            double width = viewport.Width;

            Recursion(context, x, y, width, Iterations);
        }
        public override void Render(IGraphics2DContext context)
        {
            int n;

            double w = context.Viewport.Width;
            double h = context.Viewport.Height;

            double logBailOut = Math.Log(BailOut);
            double bailOutSq  = BailOut * BailOut;

            double step     = Math.Max(Region.Width / w, Region.Height / h);
            double offset_x = Region.X - (w * step - Region.Width) / 2.0;
            double offset_y = Region.Y - (h * step - Region.Height) / 2.0;

            double x2 = 0, y2 = 0;
            double C_Re, C_Im;
            double Z_Re, Z_Im;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    C_Re = offset_x + x * step;
                    C_Im = offset_y + y * step;

                    Z_Re = C_Re;
                    Z_Im = C_Im;

                    for (n = 0; n < MaxIterations; n++)
                    {
                        x2 = Z_Re * Z_Re;
                        y2 = Z_Im * Z_Im;

                        if (x2 + y2 > bailOutSq)
                        {
                            break;
                        }

                        Z_Im = Z_Re * Z_Im * 2 + C_Im;
                        Z_Re = x2 - y2 + C_Re;
                    }

                    if (n < MaxIterations)
                    {
                        double mu = n - Math.Log(Math.Log(Math.Sqrt(x2 + y2)) / logBailOut, 2);
                        Color  c  = ColorPalette.GetColor(mu / MaxIterations);
                        context.PutPixel(x, y, c);
                    }
                    else
                    {
                        context.PutPixel(x, y, ColorPalette.GetColor(1));
                    }
                }
            }
        }
Exemple #6
0
        private void Recursion(IGraphics2DContext context, double x, double y, double width, int level)
        {
            if (level > 0)
            {
                double dx = width / 3;

                context.FillRectangle(x, y, width, LineHeight, Color);

                Recursion(context, x, y + LineHeight * 2, dx, level - 1);
                Recursion(context, x + 2 * dx, y + LineHeight * 2, dx, level - 1);
            }
        }
Exemple #7
0
        public override void Render(IGraphics2DContext context)
        {
            Rectangle viewport = context.Viewport;
            double    minSide  = Math.Min(viewport.Width, viewport.Height);

            double x1 = viewport.X + viewport.Width / 2 - minSide / 2;
            double x2 = x1 + minSide;
            double y1 = viewport.Y + viewport.Height / 2 - minSide / 2;
            double y2 = y1 + minSide;

            context.DrawRectangle(x1, y1, x2 - x1, y2 - y1, Color.FromArgb(0, 0, 0));
            Recursion(context, x1, y1, x2, y2, Iterations);
        }
Exemple #8
0
        public override void Render(IGraphics2DContext context)
        {
            Rectangle rect = RenderOrCalcMeasure(context, 1, false);
            double    w    = context.Viewport.Width;
            double    h    = context.Viewport.Height;

            double scale_x = w / rect.Width;
            double scale_y = h / rect.Height;

            double scale = (scale_x < scale_y) ? scale_x : scale_y;

            RenderOrCalcMeasure(context, scale, true);
        }
        public override void Render(IGraphics2DContext context)
        {
            Rectangle viewport = context.Viewport;
            double    w        = context.Viewport.Width;
            double    h        = context.Viewport.Height;

            double side = Math.Min(w, h);

            Rectangle rect = new Rectangle();

            rect.X      = viewport.X + w / 2 - side / 2;
            rect.Y      = viewport.Y + h / 2 - side / 2;
            rect.Width  = side;
            rect.Height = side;

            Recursion(context, rect.X, rect.Y, rect.Width, rect.Height, Iterations);
        }
        private void Recursion(IGraphics2DContext context, double x, double y, double width, double height, int level)
        {
            if (level > 0)
            {
                double dx = width / 3;
                double dy = height / 3;

                Recursion(context, x, y, dx, dy, level - 1);
                Recursion(context, x + 2 * dx, y, dx, dy, level - 1);
                Recursion(context, x, y + 2 * dy, dx, dy, level - 1);
                Recursion(context, x + 2 * dx, y + 2 * dy, dx, dy, level - 1);
            }
            else
            {
                context.FillRectangle(x, y, width, height, Color);
            }
        }
Exemple #11
0
        private void Recursion(IGraphics2DContext context, Point p1, Point p2, Point p3, int level)
        {
            if (level > 0)
            {
                Point p1n = new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
                Point p2n = new Point((p2.X + p3.X) / 2, (p2.Y + p3.Y) / 2);
                Point p3n = new Point((p3.X + p1.X) / 2, (p3.Y + p1.Y) / 2);

                Color color = _color ?? Color.Random();

                context.DrawLine(p1, p2, color);
                context.DrawLine(p2, p3, color);
                context.DrawLine(p3, p1, color);

                Recursion(context, p1, p1n, p3n, level - 1);
                Recursion(context, p2, p1n, p2n, level - 1);
                Recursion(context, p3, p2n, p3n, level - 1);
            }
        }
Exemple #12
0
        public override void Render(IGraphics2DContext context)
        {
            double x = 0.2;
            double y = 0.3;
            double r = Math.Sqrt(3);

            double w     = context.Viewport.Width;
            double mx    = w / 2;
            double h     = context.Viewport.Height;
            double my    = h / 2;
            double scale = Math.Min(w, h) / 7.46;

            for (int n = 0; n < Iterations; n++)
            {
                double d = Math.Pow(1 + r - x, 2.0) + y * y;

                double a0    = 3 * (1 + r - x) / d - (1 + r) / (2 + r);
                double b0    = 3 * y / d;
                double denom = a0 * a0 + b0 * b0;
                double f1x   = a0 / denom;
                double f1y   = -b0 / denom;

                switch (rand.Next(0, short.MaxValue) % 3)
                {
                case 0:
                    x = a0;
                    y = b0;
                    break;

                case 1:
                    x = -f1x / 2 - f1y * r / 2;
                    y = f1x * r / 2 - f1y / 2;
                    break;

                case 2:
                    x = -f1x / 2 + f1y * r / 2;
                    y = -f1x * r / 2 - f1y / 2;
                    break;
                }

                context.PutPixel(x * scale + mx, y * scale + my, Color);
            }
        }
        public override void Render(IGraphics2DContext context)
        {
            int n;

            double w = context.Viewport.Width;
            double h = context.Viewport.Height;

            double step     = Math.Max(Region.Width / w, Region.Height / h);
            double offset_x = Region.X - (w * step - Region.Width) / 2.0;
            double offset_y = Region.Y - (h * step - Region.Height) / 2.0;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    Complex Z    = new Complex(offset_x + x * step, offset_y + y * step);
                    Complex ZN   = Z;
                    Complex ZOld = Z;

                    double smooth_iter = Math.Exp(-Complex.Abs(Z));

                    for (n = 0; (n < MaxIterations) && (Complex.Abs(Z) < BailOut); n++)
                    {
                        ZOld = ZN;
                        ZN   = Z;
                        Z    = ZN * ZN + _c.Re + _c.Im * ZOld;

                        smooth_iter += Math.Exp(-Complex.Abs(Z));
                    }

                    if (n < MaxIterations)
                    {
                        Color c = ColorPalette.GetColor(smooth_iter / MaxIterations);
                        context.PutPixel(x, y, c);
                    }
                    else
                    {
                        context.PutPixel(x, y, ColorPalette.GetColor(1));
                    }
                }
            }
        }
Exemple #14
0
        public override void Render(IGraphics2DContext context)
        {
            UpdateColors();
            Rectangle area = RenderOrCalcMeasure(context, Point.Empty, 1, 100000, false);

            double w = context.Viewport.Width;
            double h = context.Viewport.Height;

            double scale_x = w / area.Width;
            double scale_y = h / area.Height;

            double scale = (scale_x < scale_y) ? scale_x : scale_y;

            Point loc = new Point();

            loc.X = -area.X * scale + (w - area.Width * scale) / 2;
            loc.Y = -area.Y * scale + (h - area.Height * scale) / 2;

            RenderOrCalcMeasure(context, loc, scale, Iterations, true);
        }
        public override void Render(IGraphics2DContext context)
        {
            string generator = Expander(Axiom, Rules, Iterations);

            Rectangle area = RenderOrCalcMeasure(context, generator, Angle, InitialAngle, Point.Empty, 1, false);

            double w = context.Viewport.Width;
            double h = context.Viewport.Height;

            double scale_x = w / area.Width;
            double scale_y = h / area.Height;

            double step = Math.Min(scale_x, scale_y);

            Point loc = new Point();

            loc.X = -area.X * step + (w - area.Width * step) / 2;
            loc.Y = -area.Y * step + (h - area.Height * step) / 2;

            RenderOrCalcMeasure(context, generator, Angle, InitialAngle, loc, step, true);
        }
Exemple #16
0
        private void Recursion(IGraphics2DContext context, double x1, double y1, double x2, double y2, int level)
        {
            if (level > 0)
            {
                double x1n = 2 * x1 / 3 + x2 / 3;
                double x2n = x1 / 3 + 2 * x2 / 3;
                double y1n = 2 * y1 / 3 + y2 / 3;
                double y2n = y1 / 3 + 2 * y2 / 3;

                Color color = _color ?? Color.Random();

                context.FillRectangle(x1n, y1n, x2n - x1n, y2n - y1n, color);

                Recursion(context, x1, y1, x1n, y1n, level - 1);
                Recursion(context, x1n, y1, x2n, y1n, level - 1);
                Recursion(context, x2n, y1, x2, y1n, level - 1);
                Recursion(context, x1, y1n, x1n, y2n, level - 1);
                Recursion(context, x2n, y1n, x2, y2n, level - 1);
                Recursion(context, x1, y2n, x1n, y2, level - 1);
                Recursion(context, x1n, y2n, x2n, y2, level - 1);
                Recursion(context, x2n, y2n, x2, y2, level - 1);
            }
        }
        private Rectangle RenderOrCalcMeasure(IGraphics2DContext context,
                                              string generator, double angle, double initAngle,
                                              Point loc, double step, bool render = true)
        {
            Stack <State> states = new Stack <State>();
            State         state;

            double x = loc.X;
            double y = loc.Y;

            double xn;
            double yn;

            double xmin = x;
            double ymin = y;
            double xmax = x;
            double ymax = y;

            double currAngle = initAngle;

            foreach (char c in generator)
            {
                switch (c)
                {
                case '+':
                    currAngle += angle;
                    break;

                case '-':
                    currAngle -= angle;
                    break;

                case '[':
                    states.Push(new State(currAngle, x, y));
                    break;

                case ']':
                    state     = states.Pop();
                    currAngle = state.Angle;
                    x         = state.X;
                    y         = state.Y;
                    break;

                case 'f':
                case 'F':
                    xn = x + step * Math.Cos(currAngle * Math.PI / 180);
                    yn = y + step * Math.Sin(currAngle * Math.PI / 180);

                    if (c == 'F' && render)
                    {
                        context.DrawLine(x, y, xn, yn, Color);
                    }

                    x = xn; y = yn;

                    if (x > xmax)
                    {
                        xmax = x;
                    }
                    if (x < xmin)
                    {
                        xmin = x;
                    }
                    if (y > ymax)
                    {
                        ymax = y;
                    }
                    if (y < ymin)
                    {
                        ymin = y;
                    }
                    break;

                default:
                    break;
                }
            }

            return(new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin));
        }
 public abstract void Render(IGraphics2DContext context);
Exemple #19
0
        private Rectangle RenderOrCalcMeasure(IGraphics2DContext context, Point loc, double scale, int iterations, bool render = true)
        {
            double x = 0;
            double y = 0;

            double x_min = x;
            double y_min = y;
            double x_max = x;
            double y_max = y;

            double temp_x;
            double h    = context.Viewport.Height;
            Random rand = new Random(0);

            for (int i = 0; i < iterations; i++)
            {
                double probability = rand.NextDouble();
                temp_x = x;

                double sum   = 0.0;
                Color  color = Color ?? Rendering.Color.FromArgb(0, 0, 0);

                for (int j = 0; j < System.Count; j++)
                {
                    IteratedFunction func = System[j];

                    sum += func.P;

                    if (probability <= sum)
                    {
                        x = func.A * temp_x + func.B * y + func.E;
                        y = func.C * temp_x + func.D * y + func.F;

                        color = Color ?? _colors[j];

                        if (x > x_max)
                        {
                            x_max = x;
                        }
                        if (x < x_min)
                        {
                            x_min = x;
                        }
                        if (y > y_max)
                        {
                            y_max = y;
                        }
                        if (y < y_min)
                        {
                            y_min = y;
                        }
                        break;
                    }
                }

                if (render)
                {
                    context.PutPixel(loc.X + x * scale, h - (loc.Y + y * scale), color);
                }
            }

            return(new Rectangle(x_min, y_min, x_max - x_min, y_max - y_min));
        }