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

ООП / Lab 3 Betta / lab3

.cpp
Скачиваний:
15
Добавлен:
18.02.2017
Размер:
3.19 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "lab3.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
Capture=-1;
MouseDown=false;
this->Cls();
p[0]=new CBall(200,100);
p[1]=new CBall(100,150);
p[2]=new CBall(300,200);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Cls()
{
Image1->Canvas->Pen->Width=3;
Image1->Canvas->Pen->Color = RGB(255,255,255);
Image1->Canvas->Brush->Color = RGB(255,255,255);
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);
Form1->Image1->Canvas->Pen->Width=3;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
this->Cls();
this->Draw();
for (int i=0; i < 3; i++)
{
p[i]->Draw();
};
}
//---------------------------------------------------------------------------


void __fastcall TForm1::OnMouseDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
MouseDown=true;
Capture=-1;
for (int i=0; i < 3; i++) {
if (sqrt((X-p[i]->GetX())*(X-p[i]->GetX())+(Y-p[i]->GetY())*(Y-p[i]->GetY()))<=p[i]->GetR())
{
Capture=i;
dx=p[Capture]->GetX()-X;
dy=p[Capture]->GetY()-Y;
}
}

}
//---------------------------------------------------------------------------


void __fastcall TForm1::OnMouseUp(TObject *Sender, TMouseButton Button,
	  TShiftState Shift, int X, int Y)
{
MouseDown=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::OnMouseMove(TObject *Sender, TShiftState Shift, int X,
	  int Y)
{
 if ((MouseDown) && (Capture!=-1)&& ((X>10) && (Y>10) && (X<Image1->Width-10) && (Y<Image1->Height-10)))
   {
	if(Capture==0)
		{
		p[0]->SetX(X+dx);
		p[0]->SetY(dy+Y);
		}
	if(Capture==1)
		{
		p[1]->SetX(X+dx);
		p[1]->SetY(dy+Y);
		}
	if(Capture==2)
		{
		p[2]->SetX(X+dx);
		p[2]->SetY(dy+Y);
		}
	}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Draw()
{

Form1->Image1->Canvas->Pen->Width=3;
Form1->Image1->Canvas->Pen->Color = clRed;
Form1->Image1->Canvas->Brush->Color = clRed;

bool t=true;
double x0,y0;
double x = 0, y = 0, x1 = 0, x2 = 0, x3 = 0;
for (int ii = 0; ii < 100; ii++)
{
double i=ii*0.01;
//x=(1-i)*(1-i)*p[0]->GetX()+2*i*(1-i)*p[1]->GetX()+i*i*p[2]->GetX();
//y=(1-i)*(1-i)*p[0]->GetY()+2*i*(1-i)*p[1]->GetY()+i*i*p[2]->GetY();
x=(p[0]->GetX()*(1-i)*(1-i)+p[1]->GetX()*(1+2*i-2*i*i)+p[2]->GetX()*i*i)/2;
y =(p[0]->GetY()*(1-i)*(1-i)+p[1]->GetY()*(1+2*i-2*i*i)+p[2]->GetY()*i*i)/2;
if (t)
{
	x0=x;
	y0=y;
};
Form1->Image1->Canvas->MoveTo(x0,y0);
Form1->Image1->Canvas->LineTo(x,y);
x0=x; y0=y;
t=false;
};

}

//---------------------------------------------------------------------------

Соседние файлы в папке Lab 3 Betta