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

ООП / Laba3_3 / Lab3

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

#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;

p[0]=new CBall(200-3.14*50,200);
p[1]=new CBall(200+1.57*50,150);
p[2]=new CBall(514,200);

this->Cls();
}
//---------------------------------------------------------------------------

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);
}
//---------------------------------------------------------------------------

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)
{
int X2;
if ((MouseDown) && (Capture!=-1)) {
if(Capture!=1)
{
if(Capture==0)
{
X2=p[0]->GetX();
p[0]->SetX(X+dx);
p[2]->SetX(p[2]->GetX()+(X2-p[0]->GetX())*2);
}
if(Capture==2)
{
X2=p[2]->GetX();
p[2]->SetX(X+dx);
p[0]->SetX(p[0]->GetX()+(X2-p[2]->GetX())/2);
}
}
if(Capture==1)p[Capture]->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;
int x0,y0,a=1,w=1 ;
double x,y, T;
for (int ii = -314; ii < 628; ii++) {
double i=ii*0.01;
T=0.02*(p[2]->GetX()-p[0]->GetX());
//ShowMessage(p[2]->GetX()-p[0]->GetX());
x=(p[2]->GetX()-p[0]->GetX())*i*0.106+200; y=(p[1]->GetY()-200)*sin(i)+200;
if (ii==157) p[1]->SetX(x);
if (t) { x0=x; y0=y;};
Form1->Image1->Canvas->MoveTo(x0,y0);
Form1->Image1->Canvas->LineTo((int)x,(int)y);
x0=x; y0=y;
t=false;
};

}




Соседние файлы в папке Laba3_3