Mam taki programik:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "bezier.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for (int i = 0; i <=Image1->Height; i++)
for (int j = 0; j <= Image1->Width; j++)
Image1->Canvas->Pixels[i][j]=0xFFFFFF;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int Ax=StrToInt(Edit1->Text);
int Ay=StrToInt(Edit2->Text);
int Bx=StrToInt(Edit3->Text);
int By=StrToInt(Edit4->Text);
int Cx=StrToInt(Edit5->Text);
int Cy=StrToInt(Edit6->Text);
int Dx=StrToInt(Edit7->Text);
int Dy=StrToInt(Edit8->Text);
Image1->Canvas->Pen->Color = clBlue;
Image1->Canvas->Pen->Style = psSolid;
Image1->Canvas->Pen->Width=3;
Image1->Canvas->MoveTo(Ax,Ay);
for (float t=0.00; t <= 1; t=t+0.01)
{
float Px=Ax*pow(1-t,3)+3*Bx*t*pow(1-t,2)+3*Cx*pow(t,2)*(1-t)+Dx*pow(t,3);
float Py=Ay*pow(1-t,3)+3*By*t*pow(1-t,2)+3*Cy*pow(t,2)*(1-t)+Dy*pow(t,3);
Image1->Canvas->LineTo(Px,Py);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
for (int i = 0; i <= Image1->Height; i++)
for (int j = 0; j <= Image1->Width; j++)
Image1->Canvas->Pixels[i][j]=0xFFFFFF;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
int Ax=StrToInt(Edit1->Text);
int Ay=StrToInt(Edit2->Text);
int Bx=StrToInt(Edit3->Text);
int By=StrToInt(Edit4->Text);
int Cx=StrToInt(Edit5->Text);
int Cy=StrToInt(Edit6->Text);
Image1->Canvas->Pen->Color = clGreen;
Image1->Canvas->Pen->Style = psSolid;
Image1->Canvas->Pen->Width=3;
Image1->Canvas->MoveTo(Ax,Ay);
for (float t=0.00; t <= 1; t=t+0.01)
{
float Px=pow(1-t,2)*Ax+2*(1-t)*t*Bx+pow(t,2)*Cx;
float Py=pow(1-t,2)*Ay+2*(1-t)*t*By+pow(t,2)*Cy;
Image1->Canvas->LineTo(Px,Py);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
int Ax=StrToInt(Edit1->Text);
int Ay=StrToInt(Edit2->Text);
int Bx=StrToInt(Edit3->Text);
int By=StrToInt(Edit4->Text);
Image1->Canvas->Pen->Color = clRed;
Image1->Canvas->Pen->Style = psSolid;
Image1->Canvas->Pen->Width=3;
Image1->Canvas->MoveTo(Ax,Ay);
for (float t=0.00; t <= 1; t=t+0.01)
{
float Px=(1-t)*Ax+t*Bx;
float Py=(1-t)*Ay+t*By;
Image1->Canvas->LineTo(Px,Py);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
int srx=StrToInt(Edit9->Text);
int sry=StrToInt(Edit10->Text);
int pion=StrToInt(Edit11->Text)/2;
int poz=StrToInt(Edit12->Text)/2;
for (float i = 0.000; i < 6.28; i=i+0.001){
float x=sin(i)*pion+srx;
float y=cos(i)*poz+sry;
// moveto(x,y);
Image1->Canvas->Pixels[x][y]=0x000000;
}
}
//---------------------------------------------------------------------------
Teraz chciałbym go nieco ulepszyć. Chciałbym za pomocą myszki umieszczać puknty na obiekcie Image1 i powiedzmy po kliknięciu niech zczytaną pozycję zapiszę do jakiejś tablicy (chyba, że macie jakieś inne pomysły). Nie wiem jak to zrobić. Możecie pomóc?