Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
#define STRICT
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <windowsx.h>
#include <conio.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;
}
char const szClassName[] = "TEXT";
char const szWindowTitle[] = "Text examples";
BOOL RegisterApp (HINSTANCE);
HWND CreateApp (HINSTANCE, int);
LRESULT CALLBACK _export WndProc (HWND,UINT,WPARAM,LPARAM);
void Line_OnDestroy(HWND);
void Line_OnPaint(HWND);
#pragma argused
int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
MSG msg;
if(!RegisterApp(hInst)) return FALSE;
if(!CreateApp(hInst, nCmdShow)) return FALSE;
while (GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//---------------------------------------------------
BOOL RegisterApp (HINSTANCE hInst)
{
WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = GetStockBrush(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
return RegisterClass(&wc);
}
//----------------------------------------------------
HWND CreateApp (HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd;
hwnd = CreateWindow (szClassName, szWindowTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL) return hwnd;
ShowWindow (hwnd,nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
//----------------------------------------------------
LRESULT CALLBACK _export WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
HANDLE_MSG (hwnd, WM_DESTROY, Line_OnDestroy);
HANDLE_MSG (hwnd, WM_PAINT, Line_OnPaint);
default: return DefWindowProc (hwnd, msg, wParam, lParam);
}
}
//----------------------------------------------------
void Line_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
void Line_OnPaint (HWND hwnd)
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint (hwnd, &ps);
inittext();
Matrix3 temp, trans;
point coord;
int tox=140;
char star[]="*";
SetBkColor(hdc,RGB(255,255,255));
// getch();
for(int j=0; j<tox; j++)
{
SetTextColor(hdc, RGB(0,0,0));
for(int i=0; i<MAXSYMB; i++)
{
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*T(j,0);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
for(int k=0; k<10; k++) {}
SetTextColor(hdc, RGB(255,255,255));
for(i=0; i<MAXSYMB; i++) {
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*T(j,0);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
}
SetTextColor(hdc, RGB(0,0,0));
for(int i=0; i<MAXSYMB; i++)
{
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*R(3.14);
coord=MatrixToCoord(trans);
TextOut(hdc,tox+x0+coord.x,y0-coord.y,star,strlen(star));
}
/* for(j=0; j<360; j++)
{
SetTextColor(hdc, RGB(0,0,0));
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);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
for(int k=0; k<10; k++) {}
SetTextColor(hdc, RGB(255,255,255));
for(i=0; i<MAXSYMB; i++) {
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp;//*R(j*3.14/180);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
}
*/
EndPaint (hwnd, &ps);
}
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <windowsx.h>
#include <conio.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;
}
char const szClassName[] = "TEXT";
char const szWindowTitle[] = "Text examples";
BOOL RegisterApp (HINSTANCE);
HWND CreateApp (HINSTANCE, int);
LRESULT CALLBACK _export WndProc (HWND,UINT,WPARAM,LPARAM);
void Line_OnDestroy(HWND);
void Line_OnPaint(HWND);
#pragma argused
int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
MSG msg;
if(!RegisterApp(hInst)) return FALSE;
if(!CreateApp(hInst, nCmdShow)) return FALSE;
while (GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//---------------------------------------------------
BOOL RegisterApp (HINSTANCE hInst)
{
WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = GetStockBrush(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
return RegisterClass(&wc);
}
//----------------------------------------------------
HWND CreateApp (HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd;
hwnd = CreateWindow (szClassName, szWindowTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL) return hwnd;
ShowWindow (hwnd,nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
//----------------------------------------------------
LRESULT CALLBACK _export WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
HANDLE_MSG (hwnd, WM_DESTROY, Line_OnDestroy);
HANDLE_MSG (hwnd, WM_PAINT, Line_OnPaint);
default: return DefWindowProc (hwnd, msg, wParam, lParam);
}
}
//----------------------------------------------------
void Line_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
void Line_OnPaint (HWND hwnd)
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint (hwnd, &ps);
inittext();
Matrix3 temp, trans;
point coord;
int tox=140;
char star[]="*";
SetBkColor(hdc,RGB(255,255,255));
// getch();
for(int j=0; j<tox; j++)
{
SetTextColor(hdc, RGB(0,0,0));
for(int i=0; i<MAXSYMB; i++)
{
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*T(j,0);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
for(int k=0; k<10; k++) {}
SetTextColor(hdc, RGB(255,255,255));
for(i=0; i<MAXSYMB; i++) {
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*T(j,0);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
}
SetTextColor(hdc, RGB(0,0,0));
for(int i=0; i<MAXSYMB; i++)
{
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp*R(3.14);
coord=MatrixToCoord(trans);
TextOut(hdc,tox+x0+coord.x,y0-coord.y,star,strlen(star));
}
/* for(j=0; j<360; j++)
{
SetTextColor(hdc, RGB(0,0,0));
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);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
for(int k=0; k<10; k++) {}
SetTextColor(hdc, RGB(255,255,255));
for(i=0; i<MAXSYMB; i++) {
temp=CoordToMatrix(text[i].x,text[i].y);
trans=temp;//*R(j*3.14/180);
coord=MatrixToCoord(trans);
TextOut(hdc,x0+coord.x,y0-coord.y,star,strlen(star));
}
}
*/
EndPaint (hwnd, &ps);
}