Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / Labs 2004 / LAB3 / 4 / LAB2

.CPP
Скачиваний:
23
Добавлен:
16.04.2013
Размер:
3.53 Кб
Скачать
#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <iostream.h>
const MAXSYMB=11;
struct point{ int x,y,col; };

point text[MAXSYMB];
int x0=150, y0=150;

class Matrix3
{ public:
    double x[3][3];
    Matrix3()  { memset(x,sizeof(x),0); }
    friend Matrix3 operator *(Matrix3& A, Matrix3& B);
};

Matrix3 operator *(Matrix3& A, Matrix3& B)
{ Matrix3 res;
  for (int i=0; i<3; i++)
    for (int j=0; j<3; j++) {

      double sum=0;

      for (int k=0; k<3; k++)
	sum+=A.x[i][k]*B.x[k][j];
      res.x[i][j] = sum;
    }
  return res;
}

Matrix3 R(double fi)
{ Matrix3 res;
  res.x[0][0]=cos(fi);
  res.x[0][1]=sin(fi);
  res.x[1][0]=-sin(fi);
  res.x[1][1]=cos(fi);
  res.x[2][2]=1;
  return res;
}

Matrix3 D(double alpha, double sigma)
{ Matrix3 res;
  res.x[0][0]=alpha;
  res.x[1][1]=sigma;
  res.x[2][2]=1;
  return res;
}

Matrix3 M()
{ Matrix3 res;
  res.x[0][0]=1;
  res.x[1][1]=-1;
  res.x[2][2]=1;
  return res;
}

Matrix3 T(double lyambda, double my)
{ Matrix3 res;
  res.x[0][0]=1;
  res.x[1][1]=1;
  res.x[2][0]=lyambda;
  res.x[2][1]=my;
  res.x[2][2]=1;
  return res;
}

Matrix3 CoordToMatrix(int x, int y)
{ Matrix3 res;
  res.x[0][0]=x;
  res.x[0][1]=y;
  res.x[0][2]=1;
  return res;
}

point MatrixToCoord(Matrix3 &A)
{ point res;
  res.x=(int)A.x[0][0];
  res.y=(int)A.x[0][1];
  return res;
}

void inittext()
{   text[0].x=0; text[0].y=0;
    text[1].x=0; text[1].y=20;
    text[2].x=0; text[2].y=40;
    text[3].x=0; text[3].y=60;

    text[4].x=12; text[4].y=45;
    text[5].x=25; text[5].y=35;
    text[6].x=38; text[6].y=45;

    text[7].x=50; text[7].y=60;
    text[8].x=50; text[8].y=40;
    text[9].x=50; text[9].y=20;
    text[10].x=50; text[10].y=0;
}

void main()
{ int dr,d=DETECT;
  initgraph(&d,&dr,"c:\\borlandc\\bgi");

  inittext();
  Matrix3 temp, trans;
  point coord;

  int tox=140;
  int col=14;
  cout<<"Press any key "<<endl;
  getch();
  for(int j=0; j<tox; j++)
  {
   setcolor(col);
   for(int i=0; i<MAXSYMB; i++)
   {
    temp=CoordToMatrix(text[i].x,text[i].y);
    trans=temp*T(j,0);
    coord=MatrixToCoord(trans);
    outtextxy(x0+coord.x,y0-coord.y,"?");
   }
   delay(10);
   setcolor(BLACK);
   for(i=0; i<MAXSYMB; i++) {
    temp=CoordToMatrix(text[i].x,text[i].y);
    trans=temp*T(j,0);
    coord=MatrixToCoord(trans);
    outtextxy(x0+coord.x,y0-coord.y,"?");
   }
  }
  for(j=360; j>0; j--)
  {
   setcolor(col);
   for(int i=0; i<MAXSYMB; i++) {
     temp=CoordToMatrix(text[i].x,text[i].y);
     trans=temp*R(j*3.14/180);
     coord=MatrixToCoord(trans);
     outtextxy(tox+x0+coord.x, y0-coord.y,"?");
   }
   delay(10);
   setcolor(BLACK);
   for(i=0; i<MAXSYMB; i++) {
     temp=CoordToMatrix(text[i].x,text[i].y);
     trans=temp*R(j*3.14/180);
     coord=MatrixToCoord(trans);
     outtextxy(tox+x0+coord.x, y0-coord.y,"?");
   }
 }

  for(j=1; j<4; j++)
  {
   setcolor(col);
   for(int i=0; i<MAXSYMB; i++) {
     temp=CoordToMatrix(text[i].x,text[i].y);
     trans=temp*D(j,1);
     coord=MatrixToCoord(trans);
     outtextxy(tox+x0+coord.x, y0-coord.y,"?");
   }
   delay(500);
   setcolor(BLACK);
   for(i=0; i<MAXSYMB; i++) {
     temp=CoordToMatrix(text[i].x,text[i].y);
     trans=temp*D(j,1);
     coord=MatrixToCoord(trans);
     outtextxy(tox+x0+coord.x, y0-coord.y,"?");
   }
 }
  getch();
  closegraph();
}
Соседние файлы в папке 4
  • #
    16.04.20135.55 Кб21EGAVGA.BGI
  • #
    16.04.20133.53 Кб23LAB2.CPP
  • #
    16.04.201377.47 Кб24LAB2.EXE