Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 23.11.2009, 00:46   #1
vo_sa
Пользователь
 
Регистрация: 29.10.2008
Сообщений: 15
По умолчанию рисование астроиды (VC++ windows form aplication)

необходимо при нажатии кнопки вывести в случайном месте астроиду случайным цветом.
есть программа, которая квадрат генерирует. и есть код как строить астройду.
наверное надо использовать
DrawClosedCurve - Рисование замкнутой кривой по массиву точек

строит квадраты
Код:
#pragma once
#include "Shape.h";
namespace paint_4 {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		ArrayList^ shapes;
		Bitmap ^buffer;
		Graphics ^buffergr;
		int mX, mY;
	private: System::Windows::Forms::Button^  btnAdd;
	public: 

	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: добавьте код конструктора
			//
			shapes = gcnew ArrayList();
			SetStyle(ControlStyles::Opaque, true);
			Form1_Resize(nullptr, EventArgs::Empty);

		}

	protected:

		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	private:

		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

		void InitializeComponent(void)
		{
			this->btnAdd = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// btnAdd
			// 
			this->btnAdd->Location = System::Drawing::Point(13, 13);
			this->btnAdd->Name = L"btnAdd";
			this->btnAdd->Size = System::Drawing::Size(111, 23);
			this->btnAdd->TabIndex = 0;
			this->btnAdd->Text = L"Add";
			this->btnAdd->UseVisualStyleBackColor = true;
			this->btnAdd->Click += gcnew System::EventHandler(this, &Form1::btnAdd_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->btnAdd);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseUp);
			this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
			this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
			this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Resize);
			this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseMove);
			this->ResumeLayout(false);

		}
#pragma endregion

	private: System::Void Form1_Resize(System::Object^  sender, System::EventArgs^  e) {
				 
	     	 if (buffer != nullptr) delete buffer;
	     	 if (buffergr != nullptr) delete buffergr;
			 if (Width > 0 && Height > 0) 
			 {
				 buffer = gcnew Bitmap(Width, Height);
				 buffergr = Graphics::FromImage(buffer);
			 }

			 }
	private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
				  Shape ^s;
			 buffergr->Clear(BackColor);
			 for (int i = 0; i < shapes->Count; i++) {
				 s = (Shape^)shapes[i];
				 s->Paint(buffergr, i+1);
			 }
			 e->Graphics->DrawImageUnscaled(buffer, 0, 0);

			 }
	private: System::Void btnAdd_Click(System::Object^  sender, System::EventArgs^  e) {
				 Shape^ sh;
				 Random ^r = gcnew Random();
				 Drawing::Color c = Drawing::Color::FromArgb(255, r->Next(0, 255), r->Next(0, 255), r->Next(0, 255));
				 sh = gcnew Shape(r->Next(0, Width-150), r->Next(0, Height-150), 150, 150, c);
				 shapes->Add(sh);
				 Invalidate();

			 }
	private: System::Void Form1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
				 Shape ^s;
			 for (int i = shapes->Count-1; i >= 0 ; i--) {
				 s = (Shape^)shapes[i];
				 if (s->r.Contains(e->X, e->Y)) {
  	 				 if (e->Button == Windows::Forms::MouseButtons::Left) 
						 s->Selected = true;
					 else
						 if (e->Button == Windows::Forms::MouseButtons::Right) {
							shapes->Remove(s);
							delete s;
						 }
					 break;
				 }
			 }
			 mX = e->X;
			 mY = e->Y;
			 Invalidate();

			 }
private: System::Void Form1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			  Shape ^s;
			 for (int i = 0; i < shapes->Count; i++) {
				 s = (Shape^)shapes[i];
				 s->Selected = false;
			 }
			 Invalidate();


		 }
private: System::Void Form1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 Shape ^s;
			 for (int i = shapes->Count-1; i >= 0 ; i--) {
				 s = (Shape^)shapes[i];
				 if (s->Selected) {
					 s->r.X += e->X - mX;
					 s->r.Y += e->Y - mY;
					 Invalidate();
					 break;
				 }
			 }
			 mX = e->X;
			 mY = e->Y;

		 }
};
}
vo_sa вне форума Ответить с цитированием
Старый 23.11.2009, 00:48   #2
vo_sa
Пользователь
 
Регистрация: 29.10.2008
Сообщений: 15
По умолчанию

вот код астройды.
Код:
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

		System::Drawing::Pen^ myPen = gcnew System::Drawing::Pen(System::Drawing::Color::DarkSlateBlue);
		System::Drawing::Graphics^ formGraphics;
		formGraphics = this->CreateGraphics();
		{
			
			formGraphics->DrawString("y", gcnew Drawing::Font("Arial", 16), Brushes::Black, 508, 20);
			formGraphics->DrawString("x", gcnew Drawing::Font("Arial", 16), Brushes::Black, 780, 270);

			float x;
			float y;

			float b;
			float t;

			b = Single::Parse(mtb->Text);  //введённое число (размер астройды)
			 
				for (float i=0;i<(200*3.14);i++)
				{	
					System::Drawing::Pen^ myPen1 = gcnew System::Drawing::Pen(System::Drawing::Color::Red);
					t=(i)/100;
					x=((b*cos(t)*cos(t)*cos(t)));
					y=((b*sin(t)*sin(t)*sin(t)));	
					formGraphics->DrawLine(myPen1, x+500,y+280, x+501, y+279);	
				}

		}
		}
vo_sa вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
создание Windows Forms Aplication b-e-s Общие вопросы C/C++ 15 04.08.2009 20:06
рисование на канве и сообщения windows olchick Мультимедиа в Delphi 8 23.06.2009 14:52
не получается связать две формы использую с++ в проекте Windows Application Form (не MFC) VS2008 molodoy-pirat Windows Forms 2 23.04.2009 10:27
Form.Show в Form.Create UnD)eaD)Snake Общие вопросы Delphi 6 07.09.2007 11:13