#pragma once


namespace voronoi {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::ProgressBar^  progressBar1;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(586, 135);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(76, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Rysuj";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(586, 71);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(76, 20);
			this->textBox1->TabIndex = 1;
			this->textBox1->Text = L"10";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(583, 45);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(85, 13);
			this->label1->TabIndex = 2;
			this->label1->Text = L"Liczba punktów:";
			this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
			// 
			// progressBar1
			// 
			this->progressBar1->Location = System::Drawing::Point(575, 189);
			this->progressBar1->Name = L"progressBar1";
			this->progressBar1->Size = System::Drawing::Size(105, 23);
			this->progressBar1->TabIndex = 3;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(692, 673);
			this->Controls->Add(this->progressBar1);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

    //funkcja wyznaczająca odleglosc
	private: System::Single odleglosc(System::Int32 x1,System::Int32 y1,System::Int32 x2,System::Int32 y2)
			 {
				 return System::Math::Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
			 }

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 
				 if (System::Int16::Parse(textBox1->Text)>11) { MessageBox::Show("Maksymalnie 11 punktów","Błąd",MessageBoxButtons::OK,MessageBoxIcon::Exclamation); return;}
                array<System::Drawing::Color>^ kolory = gcnew array<System::Drawing::Color>(15);
				 kolory[0]=System::Drawing::Color::Aqua;
				 kolory[1]=System::Drawing::Color::AliceBlue;
				 kolory[2]=System::Drawing::Color::Beige;
				 kolory[3]=System::Drawing::Color::BlanchedAlmond;
				 kolory[4]=System::Drawing::Color::Chocolate;
				 kolory[5]=System::Drawing::Color::DarkSlateGray;
					 kolory[6]=System::Drawing::Color::DeepPink;
					 kolory[7]=System::Drawing::Color::Chartreuse;
					 kolory[8]=System::Drawing::Color::DarkTurquoise;
					 kolory[9]=System::Drawing::Color::DarkKhaki;
					 kolory[10]=System::Drawing::Color::DarkMagenta;
					 kolory[11]=System::Drawing::Color::DarkOrange;

				Graphics^ g1=this->CreateGraphics();
               
				// System::Int32 wspy;
				
				 array<System::Int32>^ wspx = gcnew array<System::Int32>(15);
				 array<System::Int32>^ wspy = gcnew array<System::Int32>(15);
				
				 Bitmap^ bitmapa = gcnew Bitmap(550,650);
				 Random^ liczba_los = gcnew Random();
				 for (System::Int32 i=0;i<System::Int16::Parse(textBox1->Text);i++) {
					 wspx[i]=liczba_los->Next(bitmapa->Height);
					 wspy[i]=liczba_los->Next(bitmapa->Width);
				     
					 
				 }
				  System::Int32 NajPunkt;
				  System::Single odl;
				 for (System::Int32 x=0;x<bitmapa->Width;x++)
					  for (System::Int32 y=0;y<bitmapa->Height;y++)
					  {
						  {	  
					  //poszukiwanie najblirzeszgo  punktu
				  odl=30000;
                    for (System::Int32 i=0;i<System::Int16::Parse(textBox1->Text);i++) {
						if (odleglosc(x,y,wspx[i],wspy[i])<odl) {NajPunkt=i;
						odl=odleglosc(x,y,wspx[i],wspy[i]);}
					}
					bitmapa->SetPixel(x,y,kolory[NajPunkt]);
					progressBar1->Value=x*((System::Single)1/(System::Single)bitmapa->Height)*100;//(bitmapa->Height))*100;
					//textBox1->Text=((System::Int32)((y/bitmapa->Height)*100)).ToString();
						  }
	}
				 g1->DrawImage(dynamic_cast<Image^>(bitmapa),10,10);
				
				 
			 }
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				// array<System::Int32,2>^ punkty = gcnew array<System::Int32,2>(15,2);
				
			 }
	private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
};
}

