niedziela, 22 stycznia 2017

Affine transformation (C++ Builder)



private: // User declarations
  float x1[5],y1[5],x2[5],y2[5],x3[5],y3[5];
  void __fastcall init_Random();
  float __fastcall is_Minus(float value);
  void __fastcall init_Arrays();

void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}
float __fastcall TForm1::is_Minus(float value)
{
int x;
x=rand()%12;
if(x==0)
value*=-1.;
else if(x==1)
value=0.;
else if(x==2)
value=0.;
else if(x==3)
value*=-1.;

return value;
}
void __fastcall TForm1::init_Arrays()
{
int i;
for(i=0;i<5;i++)
{
x1[i]=is_Minus((1.*(rand()%100))/100.);
x2[i]=is_Minus((1.*(rand()%100))/100.);
x3[i]=is_Minus((1.*(rand()%100))/100.);
y1[i]=is_Minus((1.*(rand()%100))/100.);
y2[i]=is_Minus((1.*(rand()%100))/100.);
y3[i]=is_Minus((1.*(rand()%100))/100.);

}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 init_Random();
 init_Arrays();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
 int i,j;
 float a,b;
 a=1.*(rand()%65535);
 b=1.*(rand()%65535);
 i=0;
 do
 {
  j=rand()%5;
  switch(j)
  {
 case 0: a=a*x1[0]+b*y1[0]+x2[0]; b=a*y2[0]+b*x3[0]+y3[0];break;
 case 1: a=a*x1[1]+b*y1[1]+x2[1]; b=a*y2[1]+b*x3[1]+y3[1];break;
 case 2: a=a*x1[2]+b*y1[2]+x2[2]; b=a*y2[2]+b*x3[2]+y3[2];break;
 case 3: a=a*x1[3]+b*y1[3]+x2[3]; b=a*y2[3]+b*x3[3]+y3[3];break;
 case 4: a=a*x1[4]+b*y1[4]+x2[4]; b=a*y2[4]+b*x3[4]+y3[4];break;
  }
  Canvas->Pixels[Form1->Width/2+Floor(40*a)][Form1->Height/2-Floor(40*b)]=RGB(rand()%255,rand()%255,rand()%255);
  i++;
}while(i<9000000);
}

Brak komentarzy:

Prześlij komentarz