#pragma endregion
private: Graphics^ g;
private: Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
Pen^ my_pen7;
Pen^ my_pen8;
private: System::Void init_Graphics()
{
g=panel1->CreateGraphics();
my_pen1=gcnew Pen(System::Drawing::Color::Red);
my_pen2=gcnew Pen(System::Drawing::Color::Brown);
my_pen3=gcnew Pen(System::Drawing::Color::Green);
my_pen4=gcnew Pen(System::Drawing::Color::Lime);
my_pen5=gcnew Pen(System::Drawing::Color::Purple);
my_pen6=gcnew Pen(System::Drawing::Color::Blue);
my_pen7=gcnew Pen(System::Drawing::Color::Black);
my_pen8=gcnew Pen(System::Drawing::Color::Orange);
}
private: System::Void draw_Triangle(int x1,int y1, int x2, int y2, int x3, int y3, Pen ^pen)
{
g->DrawLine(pen,x1,y1,x2,y2);
g->DrawLine(pen,x2,y2,x3,y3);
g->DrawLine(pen,x3,y3,x1,y1);
}
private: System::Void draw_Ellipse(int x, int y, int width, int height, Pen ^pen)
{
g->DrawEllipse(pen,x,y,width,height);
}
private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
init_Random();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
init_Graphics();
int i,j,k;
System::Int32 how_many;
int x1,y1,x2,y2,x3,y3;
int x_ellipse,y_ellipse,w,h;
how_many=Int32::Parse(textBox1->Text);
for(i=0;i<how_many;i++)
{
k=rand()%2;
if(k==0)
{
j=rand()%8;
switch(j)
{
case 0: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen1);break;
case 1: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen2);break;
case 2: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen3);break;
case 3: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen4);break;
case 4: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen5);break;
case 5: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen6);break;
case 6: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen7);break;
case 7: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen8);break;
}
}
else
{
j=rand()%8;
switch(j)
{
case 0: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen1);break;
case 1: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen2);break;
case 2: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen3);break;
case 3: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen4);break;
case 4: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen5);break;
case 5: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen6);break;
case 6: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen7);break;
case 7: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen8);break;
}
}
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}