sobota, 31 grudnia 2016

StringGrids with first numbers and random numbers in C++ Builder


private: // User declarations
bool __fastcall is_First(int x);
void __fastcall init_Random();
int *tab_first;

bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
 ++sum;
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 init_Random();
 tab_first=new int[100];
 int i,sum;
 sum=1;
 i=0;
 do
 {
if(is_First(sum))
{
tab_first[i]=sum;
++sum;
++i;
}
else
++sum;
 }while(i<100);
 int j;
 sum=0;
 for(i=0;i<10;i++)
 {
  for(j=0;j<10;j++)
   {
StringGrid1->Cells[j][i]=IntToStr(tab_first[sum]);
++sum;
   }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 delete tab_first;
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 int tab_sum[10][10];
 int temp_sum[10][10];
 int i,j;
  for(i=0;i<10;i++)
  {
   for(j=0;j<10;j++)
   {
tab_sum[i][j]=0;
temp_sum[j][i]=StrToInt(StringGrid1->Cells[j][i]);
   }
   }
  for(i=0;i<10;i++)
  {
 for(j=0;j<10;j++)
 {
 tab_sum[i][j]+=temp_sum[i][j];
 if(i>0)
  tab_sum[i][j]+=temp_sum[i-1][j];
 if(i>0 && j>0)
  tab_sum[i][j]+=temp_sum[i-1][j-1];
 if(j>0)
  tab_sum[i][j]+=temp_sum[i][j-1];
 if(i<9 && j>0)
  tab_sum[i][j]+=temp_sum[i+1][j-1];
 if(i<9)
  tab_sum[i][j]+=temp_sum[i+1][j];
 if(i<9 && j<9)
  tab_sum[i][j]+=temp_sum[i+1][j+1];
 if(j<9)
  tab_sum[i][j]+=temp_sum[i][j+1];
 if(i>0 && j<9)
  tab_sum[i][j]+=temp_sum[i-1][j+1];



 }
  }
  int k,sum_f,k1,sum_f1;
  k=0,k1=0;
  sum_f=0,sum_f1=0;
  for(i=0;i<10;i++)
  {
   for(j=0;j<10;j++)
   {
StringGrid2->Cells[i][j]=IntToStr(tab_sum[i][j]);
if(is_First(tab_sum[i][j]))
{
ListBox1->Items->Add(IntToStr(tab_sum[i][j]));
k++;
sum_f+=tab_sum[i][j];
}
else
{
ListBox2->Items->Add(IntToStr(tab_sum[i][j]));
k1++;
sum_f1+=tab_sum[i][j];
}
   }
  }
  Label2->Caption=IntToStr(k)+" elements";
  Edit1->Text=IntToStr(sum_f);
  Label5->Caption=IntToStr(k1)+" elements";
  Edit2->Text=IntToStr(sum_f1);
  int temp_random[100];
  int first_random[10];
  int sum_random[10];
  int sum_temp_random[100];
  int value_random[10];
  k=0;
  for(i=0;i<10;i++)
   {
for(j=0;j<10;j++)
{
  sum_temp_random[k]=tab_sum[i][j];
  k++;
}
   }
  i=0;
  for(j=0;j<100;j++)
   temp_random[j]=0;
  do
  {
do
{
k=rand()%100;
}while(temp_random[k]!=0);
temp_random[k]=1;
value_random[i]=k+1;
first_random[i]=tab_first[k];
sum_random[i]=sum_temp_random[k];
i++;
  }while(i<10);
  for(i=0;i<10;i++)
  {
 StringGrid3->Cells[i][0]=IntToStr(value_random[i]);
 StringGrid3->Cells[i][1]=IntToStr(first_random[i]);
 StringGrid3->Cells[i][2]=IntToStr(sum_random[i]);
  }

}

piątek, 30 grudnia 2016

The draw different numbers in the table, the sum of which is unknown in advance (Visual C++)


I want to draw the numbers in the table, the sum of which is equal to the sum previously proposed. The algorithm draws a different number when the sum is equal to the sum of the set.


#pragma endregion
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
srand(time(NULL));
int size_table, range,sum_table;
int sum_temporary;
int i,k;
size_table=Int32::Parse(textBox1->Text);
range=Int32::Parse(textBox2->Text);
sum_table=Int32::Parse(textBox3->Text);
dataGridView1->ColumnCount=size_table;
dataGridView1->RowCount=1;
dataGridView1->Rows[0]->Height=70;
array<System::Int32>^ temporary_value=gcnew array<System::Int32>(range);
array<System::Int32>^ result_value=gcnew array<System::Int32>(size_table);
for(;;)
                {
                 for(i=0;i<range;i++) 
            temporary_value[i]=0;
            sum_temporary=0;
            i=0;
           do
           {
            do
           {
        k=rand()%range;
       }while(temporary_value[k]!=0);
      temporary_value[k]=1;
         result_value[i]=k;
     sum_temporary+=k;
    i++;
        }while(i<size_table);
       if(sum_temporary==sum_table)
      break;
      }
          for(i=0;i<size_table;i++)
 dataGridView1->Rows[0]->Cells[i]->Value=result_value[i].ToString();
 textBox4->Text=sum_table.ToString();
}
};
}



niedziela, 25 grudnia 2016

Component PerformanceCounter in Visual C++



#pragma endregion
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
timer1->Enabled=false;
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
timer1->Enabled=true;
}
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {

label4->Text=Memory->NextValue().ToString()+"%";
label5->Text=Disc->NextValue().ToString()+"%";
label6->Text=CPU->NextValue().ToString()+"%";
System::Double proc_CPU;
System::Double proc_Memory;
System::Double proc_Disc;
proc_CPU=Double::Parse(CPU->NextValue().ToString());
if (proc_CPU<1.)
proc_CPU+=1;
proc_Memory=Double::Parse(Memory->NextValue().ToString());
if (proc_Memory<1.)
 proc_Memory+=1;

proc_Disc=Double::Parse(Disc->NextValue().ToString());
if (proc_Disc<1.)
 proc_Disc+=1;
progressBar1->Value=proc_Memory;
progressBar2->Value=proc_Disc;
progressBar3->Value=proc_CPU;

 
}
};
}



sobota, 17 grudnia 2016

Using Threat in programming Visual C++



#pragma endregion
private: Graphics^ my_graph1;
private: Graphics^ my_graph2;
private: Graphics^ my_graph3;
private: Graphics^ my_graph4;
private: Graphics^ my_pixels;
private: Graphics^ my_lines;
private: Pen^ my_pen1;
private: Pen^ my_pen2;
private: Pen^ my_pen3;
private: Pen^ my_pen4;
private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Void draw_Ellipse(Graphics^ graph,Pen^ pen)
{
int i,j;
for(i=3;i<77;i+=5)
graph->DrawEllipse(pen,0,0,i,i);
for(j=55;j<112;j+=8)
graph->DrawEllipse(pen,j,j,144,111);
}
private: System::Void draw_Lines(Graphics^ graph, Pen^ pen)
{
int i,j;
for(i=5;i<144;i+=5)
graph->DrawLine(pen,i,0,i,111);
for(j=5;j<111;j+=5)
graph->DrawLine(pen,0,j,144,j);

}

private: System::Void init_Lines()
{
my_lines=panel6->CreateGraphics();
Pen^ Pen_line1=gcnew Pen(System::Drawing::Color::Blue);
Pen^ Pen_line2=gcnew Pen(System::Drawing::Color::Yellow);
Pen^ Pen_line3=gcnew Pen(System::Drawing::Color::Green);
Pen^ Pen_line4=gcnew Pen(System::Drawing::Color::Purple);
int i,j;
Pen_line1->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
Pen_line2->DashStyle=System::Drawing::Drawing2D::DashStyle::Dot;
Pen_line4->DashStyle=System::Drawing::Drawing2D::DashStyle::Solid;

int margin1=5;
int margin2=15;
for(i=margin1;i<panel6->Width-margin1;i+=margin1)
my_lines->DrawLine(Pen_line1,i,margin1,i,panel6->Height-margin1);
for(j=margin1;j<panel6->Height-margin1;j+=margin2)
my_lines->DrawLine(Pen_line2,margin1,j,panel6->Width-margin1,j);
for(i=margin1;i<panel6->Width-margin1;i+=margin1)
my_lines->DrawLine(Pen_line3,i,margin1,i+margin2,panel6->Height-margin1);
for(j=margin1;j<panel6->Height-margin1;j+=margin1)
my_lines->DrawLine(Pen_line4,margin1,j,panel6->Width-margin1,j+margin2);

}
private: System::Void init_Graph()
{
my_graph1=panel1->CreateGraphics();
my_graph2=panel2->CreateGraphics();
my_graph3=panel3->CreateGraphics();
my_graph4=panel4->CreateGraphics();
my_pen1=gcnew Pen(System::Drawing::Color::Black);
my_pen2=gcnew Pen(System::Drawing::Color::Yellow);
my_pen3=gcnew Pen(System::Drawing::Color::Green);
my_pen4=gcnew Pen(System::Drawing::Color::Red);
draw_Lines(my_graph1,my_pen1);
draw_Lines(my_graph2,my_pen2);
draw_Lines(my_graph3,my_pen3);
draw_Lines(my_graph4,my_pen4);
draw_Ellipse(my_graph1,my_pen4);
draw_Ellipse(my_graph2,my_pen3);
draw_Ellipse(my_graph3,my_pen2);
draw_Ellipse(my_graph4,my_pen1);
 
}
private: System::Void init_Pixels()
{
my_pixels=panel5->CreateGraphics();
Bitmap^ my_bitmap=gcnew Bitmap(panel5->Width,panel5->Height);
int i,x,y;
System::Drawing::Color my_color;
for(i=0;i<100000;i++)
{
x=rand()%(panel5->Width-1)+1;
y=rand()%(panel5->Height-1)+1;
my_color=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
my_bitmap->SetPixel(x,y,my_color);
}
my_pixels->DrawImage(dynamic_cast<Image^>(my_bitmap),10,10);
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Thread^ thread_graph=gcnew Thread(gcnew ThreadStart(this,&Form1::init_Graph));
thread_graph->Start();
Thread^ thread_pixels=gcnew Thread(gcnew ThreadStart(this,&Form1::init_Pixels));
thread_pixels->Start();
Thread^ thread_lines=gcnew Thread(gcnew ThreadStart(this,&Form1::init_Lines));
thread_lines->Start();
 
}
private: System::Void panel2_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
}
};
}

wtorek, 13 grudnia 2016

Files in Windows Directory (Visual C++)



#pragma endregion
DirectoryInfo^ Windows_directory;
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
Windows_directory=gcnew DirectoryInfo("c:\\Windows" );
    }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int i;
array<FileInfo^>^dll_files=Windows_directory->GetFiles("*.dll");
array<FileInfo^>^txt_files=Windows_directory->GetFiles("*.txt");
array<FileInfo^>^prx_files=Windows_directory->GetFiles("*.prx");
array<FileInfo^>^dat_files=Windows_directory->GetFiles("*.dat");
array<FileInfo^>^applications=Windows_directory->GetFiles("*.exe");
array<FileInfo^>^etl_files=Windows_directory->GetFiles("*.etl");
array<FileInfo^>^log_files=Windows_directory->GetFiles("*.log");
array<FileInfo^>^dpx_files=Windows_directory->GetFiles("*.dpx");
array<DirectoryInfo^>^directories = Windows_directory->GetDirectories();

for(i=0;i<dll_files->Length;i++)
textBox1->AppendText(dll_files[i]->Name+" - "+dll_files[i]->Length+System::Environment::NewLine);
for(i=0;i<txt_files->Length;i++)
textBox2->AppendText(txt_files[i]->Name+" - "+txt_files[i]->Length+System::Environment::NewLine);
for(i=0;i<prx_files->Length;i++)
textBox3->AppendText(prx_files[i]->Name+" - "+prx_files[i]->Length+System::Environment::NewLine);
for(i=0;i<dat_files->Length;i++)
textBox4->AppendText(dat_files[i]->Name+" - "+dat_files[i]->Length+System::Environment::NewLine);
for(i=0;i<applications->Length;i++)
textBox5->AppendText(applications[i]->Name+" - "+applications[i]->Length+System::Environment::NewLine);
for(i=0;i<etl_files->Length;i++)
textBox6->AppendText(etl_files[i]->Name+" - "+etl_files[i]->Length+System::Environment::NewLine);
for(i=0;i<log_files->Length;i++)
textBox7->AppendText(log_files[i]->Name+" - "+log_files[i]->Length+System::Environment::NewLine);
for(i=0;i<dpx_files->Length;i++)
textBox8->AppendText(dpx_files[i]->Name+" - "+dpx_files[i]->Length+System::Environment::NewLine);
for(i=0;i<directories->Length;i++)
textBox9->AppendText(directories[i]->Name+" - "+directories[i]->CreationTime+System::Environment::NewLine);
}

};
}

piątek, 2 grudnia 2016

Transformic graphics C++ Builder to Visual C++


I translated from polish book - "C++ Builder 20 efektownych programow" - Andrzej Stasiewicz code C++ Builder to Visual C++. 

Class shared for C++ Builder and Visual C++ (scaling the image) 
scale.h
class TSkalowanie
{
private:
double A,B,C,D;
double E,F,G,H;
public:
TSkalowanie(int xe0, int ye0,int eszer,int ewys,double xr0,double yr0,
double rszer, double rwys);
int daj_ekr_x(double xr);
int daj_ekr_y(double yr);
double daj_real_x(int xe);
    double daj_real_y(int ye);
};

scale.cpp

#include <math.h>
#include "StdAfx.h"
#include "scale.h"

TSkalowanie::TSkalowanie(int xe0, int ye0, int eszer, int ewys, double xr0,
double yr0, double rszer, double rwys)
{
A=(double) eszer/rszer;
B=(double) xe0-A*(xr0-rszer/2.);
C=-(double) ewys/rwys;
D=(double)ye0-C*(yr0+rwys/2.);
E=rszer/(double)eszer;
F=xr0-rszer/2.-E*(double)xe0;
G=-rwys/(double)ewys;
H=yr0+rwys/2.-G*(double)ye0;
}
int TSkalowanie::daj_ekr_x(double x)
{
return (int)(A*x+B);
}
int TSkalowanie::daj_ekr_y(double y)
{
return (int)(C*y+D);

}
double TSkalowanie::daj_real_x(int xe)
{
return E*xe+F;
}
double TSkalowanie::daj_real_y(int ye)
{
    return G*ye+H;
}


C++ Builder

__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
 StringGrid1->Cells[0][0]="ÏFS";
 StringGrid1->Cells[1][0]="#1";
 StringGrid1->Cells[2][0]="#2";
 StringGrid1->Cells[3][0]="#3";
 StringGrid1->Cells[4][0]="#4";

 StringGrid1->Cells[0][1]="A";
 StringGrid1->Cells[1][1]="0,5";
 StringGrid1->Cells[2][1]="0,5";
 StringGrid1->Cells[3][1]="0,5";
 StringGrid1->Cells[4][1]="0,5";

 StringGrid1->Cells[0][2]="B";
 StringGrid1->Cells[1][2]="0";
 StringGrid1->Cells[2][2]="0";
 StringGrid1->Cells[3][2]="0";
 StringGrid1->Cells[4][2]="0";

 StringGrid1->Cells[0][3]="C";
 StringGrid1->Cells[1][3]="0";
 StringGrid1->Cells[2][3]="0";
 StringGrid1->Cells[3][3]="0";
 StringGrid1->Cells[4][3]="0";

 StringGrid1->Cells[0][4]="D";
 StringGrid1->Cells[1][4]="0,5";
 StringGrid1->Cells[2][4]="0,5";
 StringGrid1->Cells[3][4]="0,5";
 StringGrid1->Cells[4][4]="0";

 StringGrid1->Cells[0][5]="E";
 StringGrid1->Cells[1][5]="0";
 StringGrid1->Cells[2][5]="2";
 StringGrid1->Cells[3][5]="1";
 StringGrid1->Cells[4][5]="0";

 StringGrid1->Cells[0][6]="F";
 StringGrid1->Cells[1][6]="0";
 StringGrid1->Cells[2][6]="0";
 StringGrid1->Cells[3][6]="1,73";
 StringGrid1->Cells[4][6]="0";

 StringGrid1->Cells[0][7]="P";
 StringGrid1->Cells[1][7]="33";
 StringGrid1->Cells[2][7]="33";
 StringGrid1->Cells[3][7]="33";
 StringGrid1->Cells[4][7]="0";





}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
 Close();
}
int __fastcall TForm6::random_niesprawiedliwe(int *p, int N)
{
int i,a,suma=0,suma_wag=0;
for(i=0;i<N;i++)
suma_wag+=p[i];
a=random(suma_wag);
for(i=0;i<N;i++)
{
suma+=p[i];
if(a<suma)
break;
}
return i;
}
//---------------------------------------------------------------------------
void __fastcall TForm6::PaintBox1Paint(TObject *Sender)
{
 const int max_iter=50000, max_il_przekszt=4;
 double A[4],B[4],C[4],D[4],E[4],F[4];
 int P[4];
 TSkalowanie skal(0,0,PaintBox1->ClientWidth,PaintBox1->ClientHeight,2,2,5,5);
 int i,nr_przekszt,xe,ye;
 double x,y,x1;
 TColor kolor[]={clRed,clLime,clAqua,clFuchsia};

 for(i=0;i<max_il_przekszt;i++)
 {
A[i]=StringGrid1->Cells[i+1][1].ToDouble();
B[i]=StringGrid1->Cells[i+1][2].ToDouble();
C[i]=StringGrid1->Cells[i+1][3].ToDouble();
D[i]=StringGrid1->Cells[i+1][4].ToDouble();
E[i]=StringGrid1->Cells[i+1][5].ToDouble();
F[i]=StringGrid1->Cells[i+1][6].ToDouble();
P[i]=StringGrid1->Cells[i=1][7].ToInt();
 }
 x=0,y=0;
 for(i=0;i<max_iter;i++)
 {
nr_przekszt=random_niesprawiedliwe(P,max_il_przekszt);
x1=A[nr_przekszt]*x+B[nr_przekszt]*y+E[nr_przekszt];
y=C[nr_przekszt]*x+D[nr_przekszt]*y+F[nr_przekszt];
x=x1;

xe=skal.daj_ekr_x(x);
ye=skal.daj_ekr_y(y);

PaintBox1->Canvas->Pixels[xe][ye]=kolor[nr_przekszt];
 }

}
int __fastcall TForm6::pole_Prostokata(int a, int b)
{
int result;
result=a*b;
return result;
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button1Click(TObject *Sender)
{
 PaintBox1->Refresh();
}

Visual C++

#pragma endregion
private: System::Drawing::Color give_Color(int x)
{
if(x==0)
return System::Drawing::Color::Fuchsia;
else if(x==1)
return System::Drawing::Color::Red;
else if(x==2)
return System::Drawing::Color::Lime;
else if(x==3)
return System::Drawing::Color::Aqua;
else
return System::Drawing::Color::Blue;
}
private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Int16 random_unfair(int *p, int N)
{
int i,a,suma=0,suma_wag=0;
            for(i=0;i<N;i++)
            suma_wag+=p[i];
            a=rand()%suma_wag;
            for(i=0;i<N;i++)
            {
        suma+=p[i];
        if(a<suma)
        break;
           }
           return i;
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
dataGridView1->RowCount=8;
dataGridView1->ColumnCount=5;
int i;
for(i=0;i<dataGridView1->ColumnCount;i++)
dataGridView1->Columns[i]->Width=70;
for(i=0;i<dataGridView1->RowCount;i++)
dataGridView1->Rows[i]->Height=35;
dataGridView1->Rows[0]->Cells[0]->Value="ÏFS";
dataGridView1->Rows[0]->Cells[1]->Value="#1";
dataGridView1->Rows[0]->Cells[2]->Value="#2";
dataGridView1->Rows[0]->Cells[3]->Value="#3";
dataGridView1->Rows[0]->Cells[4]->Value="#4";


dataGridView1->Rows[1]->Cells[0]->Value="A";
dataGridView1->Rows[1]->Cells[1]->Value="0,5";
dataGridView1->Rows[1]->Cells[2]->Value="0,5";
dataGridView1->Rows[1]->Cells[3]->Value="0,5";
dataGridView1->Rows[1]->Cells[4]->Value="0";

dataGridView1->Rows[2]->Cells[0]->Value="B";
dataGridView1->Rows[2]->Cells[1]->Value="0";
dataGridView1->Rows[2]->Cells[2]->Value="0";
dataGridView1->Rows[2]->Cells[3]->Value="0";
dataGridView1->Rows[2]->Cells[4]->Value="0";

dataGridView1->Rows[3]->Cells[0]->Value="C";
dataGridView1->Rows[3]->Cells[1]->Value="0";
dataGridView1->Rows[3]->Cells[2]->Value="0";
dataGridView1->Rows[3]->Cells[3]->Value="0";
dataGridView1->Rows[3]->Cells[4]->Value="0";

dataGridView1->Rows[4]->Cells[0]->Value="D";
dataGridView1->Rows[4]->Cells[1]->Value="0,5";
dataGridView1->Rows[4]->Cells[2]->Value="0,5";
dataGridView1->Rows[4]->Cells[3]->Value="0,5";
dataGridView1->Rows[4]->Cells[4]->Value="0";

dataGridView1->Rows[5]->Cells[0]->Value="E";
dataGridView1->Rows[5]->Cells[1]->Value="0";
dataGridView1->Rows[5]->Cells[2]->Value="2";
dataGridView1->Rows[5]->Cells[3]->Value="1";
dataGridView1->Rows[5]->Cells[4]->Value="0";

dataGridView1->Rows[6]->Cells[0]->Value="F";
dataGridView1->Rows[6]->Cells[1]->Value="0";
dataGridView1->Rows[6]->Cells[2]->Value="0";
dataGridView1->Rows[6]->Cells[3]->Value="1,73";
dataGridView1->Rows[6]->Cells[4]->Value="0";

dataGridView1->Rows[7]->Cells[0]->Value="P";
dataGridView1->Rows[7]->Cells[1]->Value="33";
dataGridView1->Rows[7]->Cells[2]->Value="33";
dataGridView1->Rows[7]->Cells[3]->Value="33";
dataGridView1->Rows[7]->Cells[4]->Value="0";

 
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Graphics^ graph=panel1->CreateGraphics();
Bitmap^ bitmap=gcnew Bitmap(panel1->Width,panel1->Height);
 
const int max_iter=50000,max_il_przekszt=4;
double A[4],B[4],C[4],D[4],E[4],F[4];
int P[4];
TSkalowanie skal(0,0,panel1->Width,panel1->Height,2,2,5,5);
int i,nr_przekszt,xe,ye;
double x,y,x1;
for(i=0;i<max_il_przekszt;i++)
{
;
A[i]=Convert::ToDouble(dataGridView1->Rows[1]->Cells[i+1]->Value);
B[i]=Convert::ToDouble(dataGridView1->Rows[2]->Cells[i+1]->Value);
C[i]=Convert::ToDouble(dataGridView1->Rows[3]->Cells[i+1]->Value);
D[i]=Convert::ToDouble(dataGridView1->Rows[4]->Cells[i+1]->Value);
E[i]=Convert::ToDouble(dataGridView1->Rows[5]->Cells[i+1]->Value);
F[i]=Convert::ToDouble(dataGridView1->Rows[6]->Cells[i+1]->Value);
P[i]=Convert::ToInt16(dataGridView1->Rows[7]->Cells[i+1]->Value);

}
x=0,y=0;
for(i=0;i<max_iter;i++)
{
nr_przekszt=random_unfair(P,max_il_przekszt);
x1=A[nr_przekszt]*x+B[nr_przekszt]*y+E[nr_przekszt];
y=C[nr_przekszt]*x+D[nr_przekszt]*y+F[nr_przekszt];
x=x1;
xe=skal.daj_ekr_x(x);
ye=skal.daj_ekr_y(y);
bitmap->SetPixel(xe,ye,give_Color(nr_przekszt));
 
}
graph->DrawImage(dynamic_cast<Image^>(bitmap),10,10);

 
}
};
}