Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <vector>
- #include <math.h>
- #pragma hdrstop
- #include "Unit1.h"
- std::vector<POINT> points;
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //----------------------------GLOBAL-----------------------------------------
- //---------------------------------------------------------------------------
- int a[100],b[100]; //points coordinates
- int i=0;
- int m=0;
- double t=0.0001, tk=0.0001;
- float x=0,y=0;
- float BComb=1;
- POINT position;
- //-------------------------DrawEllipse---------------------------------------
- //---------------------------------------------------------------------------
- void DrawEllipse(int x, int y)
- {
- Form1->Image1->Canvas->Pen->Color = clTeal;
- Form1->Image1->Canvas->Ellipse(x -4, y - 4, x + 4, y + 4);
- }
- //---------------------------Factorial---------------------------------------
- //---------------------------------------------------------------------------
- int Fact(int i)
- {
- return (i<=1)? 1 : i*Fact(i-1);
- }
- //---------------------------Bernstein---------------------------------------
- //---------------------------------------------------------------------------
- float Bernstein(float t, int i)
- {
- return (pow(t,i)*pow(1-t,m-i-1))*(Fact(m-1))/((Fact(i)*Fact(m-1-i)));
- }
- //--------------------------Image1Click--------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Image1Click(TObject *Sender)
- {
- GetCursorPos(&position);
- position.x -= (Form1->Left+10);
- position.y -= (Form1->Top+30);
- points.push_back(position);
- DrawEllipse(position.x, position.y);
- a[i]=position.x;
- b[i]=position.y;
- i++;
- m++;
- }
- //-----------------------Button1Click---------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- Image1->Canvas->Pen->Style=psDot;
- Form1->Image1->Canvas->Pen->Color = clPurple;
- Form1->Image1->Canvas->MoveTo(a[0], b[0]);
- for(int i = 0; i < m; i++)
- {
- Form1->Image1->Canvas->LineTo(a[i], b[i]);
- }
- Form1->Image1->Canvas->Pen->Style=psSolid;
- }
- //-----------------------Button2Click---------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- /* if(ColorDialog1->Execute())
- Form1->Canvas->Pen->Color=ColorDialog1->Color;
- */
- Form1->Image1->Canvas->Pen->Style=psSolid;
- Form1->Image1->Canvas->Pen->Color = clSkyBlue;
- Form1->Image1->Canvas->MoveTo(a[0], b[0]);
- for(t=0;t<1;t+=tk)
- {
- float x=pow((1-t),3)*a[0] + 3*pow((1-t),2)*t*a[1]
- +3*(1-t)*pow(t,2)*a[2] + pow(t,3)*a[3];
- float y=pow((1-t),3)*b[0] + 3*pow((1-t),2)*t*b[1]
- +3*(1-t)*pow(t,2)*b[2] + pow(t,3)*b[3];
- Form1->Image1->Canvas->LineTo(x, y);
- }
- }
- //-----------------------Button3Click---------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- /* if(ColorDialog1->Execute())
- Form1->Canvas->Pen->Color=ColorDialog1->Color;
- */
- x=0;y=0;
- for(t=0.00001;t<1;t+=tk)
- {
- for(int i=0;i<m;i++)
- {
- x+=Bernstein(t,i)*a[i];
- y+=Bernstein(t,i)*b[i];
- }
- Form1->Image1->Canvas->Pixels[x][y]=clBlack;
- x=0;y=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement