Код Фримэна на Builder C++

Код Фримэна: объект — совокупность отрезков. Экран разбивается на клетке и происходит кодирование с помощью векторов.
Длина вектора: T(корень из 2)



Была разработана программа реализующая построение объектов с помощью кодов Фримена.

Код программы:

//—————————————————————————

#include
#include #pragma hdrstop

#include «Unit1.h»
//—————————————————————————
#pragma package(smart_init)
#pragma resource «*.dfm»
int dx;
int fig[8][2], nfig, fig1[8][2],fig2[8][2],nfig1,nfig2,newfig1[8][2],newfig2[8][2];
double k=0,k2=0;
TForm1 *Form1;
//—————————————————————————
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//—————————————————————————

void __fastcall TForm1::Button1Click(TObject *Sender)
{
//TColor pole;
int h,w,i,j;
h=Image1->Height;
w=Image1->Width;

//————Удаляем старую сетку————
Image1->Canvas->Pen->Color = clWhite;
for(i=1;i<=w/dx;i++) { Image1->Canvas->MoveTo(i*dx,0);
Image1->Canvas->LineTo(i*dx,h);
}
for(j=1;j<=h/dx;j++) { Image1->Canvas->MoveTo(0,j*dx);
Image1->Canvas->LineTo(w,j*dx);
}
//—————-Конец——————-

Image1->Canvas->Pen->Color = clBlack;
Image1->Canvas->Pen->Style = psDashDot;
Image1->Canvas->Pen->Width = 1;
dx=StrToInt(Edit1->Text);

//————Создаем сетку————
for(i=1;i<=w/dx;i++) { Image1->Canvas->MoveTo(i*dx,0);
Image1->Canvas->LineTo(i*dx,h);
}
for(j=1;j<=h/dx;j++) { Image1->Canvas->MoveTo(0,j*dx);
Image1->Canvas->LineTo(w,j*dx);
}
//—————-Конец——————-

}
//—————————————————————————
void __fastcall TForm1::FormCreate(TObject *Sender)
{
dx=StrToInt(Edit1->Text);
Image1->Canvas->Pen->Color = clBlack;
Image2->Canvas->Pen->Color = clBlack;
int h,w;
h=Image2->Height;
w=Image2->Width;
Image2->Canvas->MoveTo(0,0);
Image2->Canvas->LineTo(w,h);
Image2->Canvas->MoveTo(0,h);
Image2->Canvas->LineTo(w,0);
Image2->Canvas->MoveTo(w/2,0);
Image2->Canvas->LineTo(w/2,h);
Image2->Canvas->MoveTo(0,h/2);
Image2->Canvas->LineTo(w,h/2);
}
//—————————————————————————

void __fastcall TForm1::Button2Click(TObject *Sender)
{
int h,w,temph,tempw,r,rec[8],dx=35,i,starth,startw;
h=Image1->Height;
w=Image1->Width;
temph=starth=h/2-70;
tempw=startw=w/2-140;
r=StrToInt(Edit2->Text);
if(r>=77777777) {ShowMessage («Error. Repeat enter»); goto exit;}
rec[0]=r/10000000;
rec[1]=r%10000000/1000000;
rec[2]=r%1000000/100000;
rec[3]=r%100000/10000;
rec[4]=r%10000/1000;
rec[5]=r%1000/100;
rec[6]=r%100/10;
rec[7]=r%10;
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Pen->Width = 3;
Image1->Canvas->Pen->Style = psSolid;
for (i=0; i<8;i++) { switch (rec[i]) { case 0: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw+dx,temph);
fig[i][0]=tempw;
fig[i][1]=temph;
tempw+=dx;
break;
case 1: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw+dx,temph-dx);
fig[i][0]=tempw;
fig[i][1]=temph;
tempw+=dx;
temph-=dx;
break;
case 2: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw,temph-dx);
fig[i][0]=tempw;
fig[i][1]=temph;
temph-=dx;
break;
case 3: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw-dx,temph-dx);
fig[i][0]=tempw;
fig[i][1]=temph;
temph-=dx;
tempw-=dx;
break;
case 4: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw-dx,temph);
fig[i][0]=tempw;
fig[i][1]=temph;
tempw-=dx;
break;
case 5: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw-dx,temph+dx);
fig[i][0]=tempw;
fig[i][1]=temph;
tempw-=dx;
temph+=dx;
break;
case 6: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw,temph+dx);
fig[i][0]=tempw;
fig[i][1]=temph;
temph+=dx;
break;
case 7: Image1->Canvas->MoveTo(tempw,temph);
Image1->Canvas->LineTo(tempw+dx,temph+dx);
fig[i][0]=tempw;
fig[i][1]=temph;
temph+=dx;
tempw+=dx;
break;
}
}
if ((starth!=temph)&&(startw!=tempw))
//ShowMessage(«Ready»);
ShowMessage(«Return please»);
exit:;
}
//—————————————————————————

void __fastcall TForm1::Button3Click(TObject *Sender)
{
k=0;
Image1->Canvas->Pen->Color=clWhite;
Image1->Canvas->Pen->Width = 2;
for(int i=0;i<420;i++) { Image1->Canvas->MoveTo(i,0);
Image1->Canvas->LineTo(i+1,Image1->Height);
}
}
//—————————————————————————

void __fastcall TForm1::Button4Click(TObject *Sender)
{
//—————-Чертим линию разделения——————-
Image1->Canvas->Pen->Color=clGreen;
Image1->Canvas->Pen->Width = 3;
Image1->Canvas->Pen->Style = psSolid;

Image1->Canvas->MoveTo(fig[StrToInt(Edit3->Text)][0],fig[StrToInt(Edit3->Text)][1]);
Image1->Canvas->LineTo(fig[StrToInt(Edit4->Text)][0],fig[StrToInt(Edit4->Text)][1]);
//nfig=StrToInt(Edit4->Text)-StrToInt(Edit3->Text)+1;
int i;
//—————Записываем координаты 2ух фигур—————————
nfig1=0;nfig2=0;
for(i=0;i<8;i++) { if(i>=StrToInt(Edit3->Text) && i<=StrToInt(Edit4->Text))
{
fig1[nfig1][0]=fig[i][0];
fig1[nfig1][1]=fig[i][1];
nfig1++;
}
if(i>=StrToInt(Edit4->Text) || i<=StrToInt(Edit3->Text))
{
fig2[nfig2][0]=fig[i][0];
fig2[nfig2][1]=fig[i][1];
nfig2++;
}
}
//—————-Конец——————-
}
//—————————————————————————

//—————-Масштабирование——————-
void __fastcall TForm1::Button5Click(TObject *Sender)
{
int i;
//—————-Удаляем старые результаты——————-
if ((k!=0)||(k2!=0))
{
Button3Click(Form1);
Button1Click(Form1);
Button2Click(Form1);
Button4Click(Form1);
}
//—————Конец———————

//—————-Начало масштабирования——————-
Image1->Canvas->Pen->Color=clFuchsia;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Pen->Style = psSolid;
//—————-Масштабирование fig1——————-
k=StrToFloat(Edit5->Text);
for(i=0;iCanvas->MoveTo(newfig1[i][0],newfig1[i][1]);
Image1->Canvas->LineTo(newfig1[i+1][0],newfig1[i+1][1]);
}
Image1->Canvas->MoveTo(newfig1[nfig1-1][0],newfig1[nfig1-1][1]);
Image1->Canvas->LineTo(newfig1[0][0],newfig1[0][1]);
}
//—————————————————————————

void __fastcall TForm1::Button6Click(TObject *Sender)
{
Form1->Close();
}
//—————————————————————————

void __fastcall TForm1::Button7Click(TObject *Sender)
{
int i;
//—————-Удаляем старые результаты 2——————-
if ((k!=0)||(k2!=0))
{
Button3Click(Form1); //Стираем
Button1Click(Form1); //Сетка
Button2Click(Form1); //Фигура
Button4Click(Form1); //Линия разделения
}
//—————Конец———————

//—————-Начало масштабирования 2——————-
Image1->Canvas->Pen->Color = clPurple;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Pen->Style = psSolid;
//—————-Масштабирование fig2——————-
k2=StrToFloat(Edit6->Text);
if (RadioGroup1->ItemIndex==0)
for(i=0;iCanvas->MoveTo(newfig2[i][0],newfig2[i][1]);
Image1->Canvas->LineTo(newfig2[i+1][0],newfig2[i+1][1]);
}
Image1->Canvas->MoveTo(newfig2[nfig2-1][0],newfig2[nfig2-1][1]);
Image1->Canvas->LineTo(newfig2[0][0],newfig2[0][1]);
}
//—————————————————————————

void __fastcall TForm1::Button8Click(TObject *Sender)
{
//—————————Поворот——————
if ((k!=0)||(k2!=0))
{
Button3Click(Form1);
Button1Click(Form1);
Button2Click(Form1);
Button4Click(Form1);
}
int i,tempnewfig1[8][2];
double a;
i=StrToInt(Edit7->Text);
a=(-1)*M_PI*i/180.0;
if(i==90) a=-M_PI_2;
if(i==45) a=-M_PI_4;
if(i==30) a=-M_PI_4/3.0;
k=StrToFloat(Edit5->Text);

Image1->Canvas->Pen->Color=clFuchsia;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Pen->Style = psSolid;
//——————Перенос в начало координат————
int tempx=newfig1[0][0], tempy=newfig1[0][1];

for(i=0;iCanvas->MoveTo(newfig1[i][0],newfig1[i][1]);
Image1->Canvas->LineTo(newfig1[i+1][0],newfig1[i+1][1]);
}
Image1->Canvas->MoveTo(newfig1[nfig1-1][0],newfig1[nfig1-1][1]);
Image1->Canvas->LineTo(newfig1[0][0],newfig1[0][1]);
}
//—————————————————————————

void __fastcall TForm1::Button9Click(TObject *Sender)
{
int i;
//——————Поворот—————
if ((k!=0)||(k2!=0))
{
Button3Click(Form1);
Button1Click(Form1);
Button2Click(Form1);
Button4Click(Form1);
for(i=0;iCanvas->Pen->Color = clPurple;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Pen->Style = psSolid;
Image1->Canvas->MoveTo(newfig2[i][0],newfig2[i][1]);
Image1->Canvas->LineTo(newfig2[i+1][0],newfig2[i+1][1]);
}
Image1->Canvas->MoveTo(newfig2[nfig2-1][0],newfig2[nfig2-1][1]);
Image1->Canvas->LineTo(newfig2[0][0],newfig2[0][1]);
}

Image1->Canvas->Pen->Color = clHotLight;
Image1->Canvas->Pen->Width = 3;
Image1->Canvas->Pen->Style = psSolid;
Image1->Canvas->MoveTo(0,3);
Image1->Canvas->LineTo(417,420);

Image1->Canvas->Pen->Color = clPurple;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Pen->Style = psSolid;

int tempnewfig2[8][2];

//————Перенос на три вверх————
for(i=0;iCanvas->MoveTo(newfig2[i][0],newfig2[i][1]);
Image1->Canvas->LineTo(newfig2[i+1][0],newfig2[i+1][1]);
}
Image1->Canvas->MoveTo(newfig2[nfig2-1][0],newfig2[nfig2-1][1]);
Image1->Canvas->LineTo(newfig2[0][0],newfig2[0][1]);
}
//—————————————————————————

void __fastcall TForm1::Button10Click(TObject *Sender)
{
Button5Click(Form1);
Button8Click(Form1);
}
//—————————————————————————

void __fastcall TForm1::Button11Click(TObject *Sender)
{
Button7Click(Form1);
Button9Click(Form1);
}
//—————————————————————————


Комментарии запрещены.





Статистика

Рейтинг@Mail.ru