Пример #1
0
        //+(-) - поворот по (против) часовой стрелке на угол
        //F,G,D - рисуют прямую
        public Bitmap DrawFractal(string fractal, double direction, double angle, int length, Bitmap bm)
        {
            if (fractal == null)
            {
                return(bm);
            }
            MyPoint p1 = new MyPoint(bm.Width / 2, bm.Height / 2);
            MyPoint p2 = new MyPoint(bm.Width / 2, bm.Height / 2 - length);
            Stack <KeyValuePair <MyPoint, double> > s = new Stack <KeyValuePair <MyPoint, double> >();

            for (int i = 0; i < fractal.Length; ++i)
            {
                if (fractal[i] == '+')
                {
                    direction += angle;
                }
                if (fractal[i] == '-')
                {
                    direction -= angle;
                }
                if (fractal[i] == 'F' || fractal[i] == 'G' || fractal[i] == 'D')
                {
                    p2.RotationPoint(p1, direction);
                    if (0 < p1.X && 0 < p1.Y && 0 < p2.X && 0 < p2.Y && bm.Width > p1.X && bm.Height > p1.Y && bm.Width > p2.X && bm.Height > p2.Y)
                    {
                        bm = MyEdge.DrawEdge(bm, p1, p2);
                    }
                    p1 = p2;
                    p2 = new MyPoint(p1.X, p1.Y - length);
                }
                if (fractal[i] == '[')
                {
                    s.Push(new KeyValuePair <MyPoint, double>(p1, direction));
                }
                if (fractal[i] == ']')
                {
                    p1        = s.Peek().Key;
                    direction = s.Pop().Value;
                    p2        = new MyPoint(p1.X, p1.Y - length);
                }
            }
            return(bm);
        }
Пример #2
0
 public void RotationEdge(MyPoint p, double rotation)
 {
     p1.RotationPoint(p, rotation);
     p2.RotationPoint(p, rotation);
 }