예제 #1
0
 /// <summary>
 /// Перерисовываем pictureBox
 /// </summary>
 private void redrawImage()
 {
     g.Clear(Color.White);
     foreach (edge e in edges)
     {
         draw_edge(pen, e);
     }
     pictureBox.Image = bmp;
     center_point     = centerPoint();
 }
예제 #2
0
        // поворот
        private void rotate(My_point p, My_point rotatePoint, double a)
        {
            double angle = (a * Math.PI) / 180;

            p.X -= rotatePoint.X;
            p.Y -= rotatePoint.Y;
            double xa = p.X * Math.Cos(angle) + p.Y * Math.Sin(angle);
            double ya = p.Y * Math.Cos(angle) - p.X * Math.Sin(angle);

            p.X = xa + rotatePoint.X;
            p.Y = ya + rotatePoint.Y;
        }
예제 #3
0
        // построение фрактала
        private void make_fract(string fileName, int level)
        {
            LSystem       lsys         = new LSystem(fileName);
            string        actions      = lsys.getResult(level);
            double        angle        = lsys.rotateAngle;
            Stack <State> stack        = new Stack <State>();
            State         currentState = new State(0, new My_point(0, 0), new My_point(40, 0));

            for (int i = 0; i < actions.Length; i++)
            {
                if (actions[i] == 'F')
                {
                    My_point p1 = new My_point(currentState.prevPoint.X, currentState.prevPoint.Y);
                    My_point p2 = new My_point(currentState.nextPoint.X, currentState.nextPoint.Y);
                    edges.Add(new edge(p1, p2));
                    currentState.prevPoint.X = currentState.nextPoint.X;
                    currentState.prevPoint.Y = currentState.nextPoint.Y;
                    displacement(currentState.nextPoint, 40, 0);
                    rotate(currentState.nextPoint, currentState.prevPoint, currentState.angle);
                }
                else if (actions[i] == '-')
                {
                    rotate(currentState.nextPoint, currentState.prevPoint, angle);
                    currentState.angle += angle;
                }
                else if (actions[i] == '+')
                {
                    rotate(currentState.nextPoint, currentState.prevPoint, -angle);
                    currentState.angle -= angle;
                }
                else if (actions[i] == '[')
                {
                    stack.Push(new State(currentState.angle,
                                         new My_point(currentState.prevPoint.X, currentState.prevPoint.Y),
                                         new My_point(currentState.nextPoint.X, currentState.nextPoint.Y)));
                }
                else if (actions[i] == ']')
                {
                    State prevState = stack.Pop();
                    currentState.angle     = prevState.angle;
                    currentState.prevPoint = prevState.prevPoint;
                    currentState.nextPoint = prevState.nextPoint;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Изменение масштаба заданной фигуры
        /// </summary>
        private void butt_sc_Click(object sender, EventArgs e)
        {
            My_point center = centerPoint();
            double   kx     = (double)set_sc_x.Value;
            double   ky     = (double)set_sc_y.Value;

            center_point = centerPoint();
            foreach (My_point p in points)
            {
                p.X -= center_point.X;
                p.Y -= center_point.Y;
                p.X  = (int)(p.X * kx);
                p.Y  = (int)(p.Y * ky);
                p.X += center_point.X;
                p.Y += center_point.Y;
            }
            redrawImage();
        }
예제 #5
0
 public State(double a, My_point pp, My_point np)
 {
     angle     = a;
     prevPoint = pp;
     nextPoint = np;
 }
예제 #6
0
 public bool contains(My_point p)
 {
     return(p == P1 || p == P2);
 }
예제 #7
0
 public edge(My_point p1, My_point p2)
 {
     P1 = p1; P2 = p2;
 }
예제 #8
0
 // смещение
 private void displacement(My_point p, int kx, int ky)
 {
     p.X += kx;
     p.Y += ky;
 }