1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
| #pragma once
namespace WA {
#define _USE_MATH_DEFINES
#include <math.h>
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>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Timer^ timer1;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Требуется переменная конструктора.
cli::array<System::Drawing::PointF>^p1, ^p2;
float xc, yc, r, x, y, dx, dy;
int xmin, ymin, xmax, ymax;
void ris (Graphics^gr,SolidBrush^rb,SolidBrush^rb1,cli::array<System::Drawing::PointF>^p1)
{
gr->FillPolygon(rb,p1);
gr->FillPolygon(rb1,p1);
}
void move(double x, double y)
{
x -= 1.5;
y -= 1.5;
}
void rotate(cli::array<System::Drawing::PointF>^p1, cli::array<System::Drawing::PointF>^p2)
{
double phi = 12 * M_PI / 180;
double cs = cos(phi);
double sn = sin(phi);
for (int i = 0; i < 2; i++)
{
double dx, dy;
dx = p1[i].X - xc;
dy = p1[i].Y - yc;
p1[i].X = xc + dx*cs - dy*sn;
p1[i].Y = xc + dx*sn + dy*cs;
dx = p2[i].X - xc;
dy = p2[i].Y - yc;
p2[i].X = xc + dx*cs - dy*sn;
p2[i].Y = xc + dx*sn + dy*cs;
}
}
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->SuspendLayout();
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(204)));
this->button1->Location = System::Drawing::Point(436, 160);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(87, 36);
this->button1->TabIndex = 0;
this->button1->Text = L"Ввод";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button3
//
this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(204)));
this->button3->Location = System::Drawing::Point(436, 244);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(87, 36);
this->button3->TabIndex = 2;
this->button3->Text = L"Пуск/стоп";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(436, 91);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 3;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(204)));
this->label1->Location = System::Drawing::Point(433, 75);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(102, 16);
this->label1->TabIndex = 4;
this->label1->Text = L"Ввод данных";
//
// timer1
//
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(592, 409);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button3);
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
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
p1->Resize(p1, 3);
p2->Resize(p2, 3);
xc = yc = 200;
r = 100;
p1[0].X = xc - r;
p1[0].Y = yc - r;
p1[1].X = xc - r;
p1[1].Y = yc + r;
p1[2].X = xc + r;
p1[2].Y = yc - r;
p2[0].X = xc - r;
p2[0].Y = yc - r;
p2[1].X = xc - r;
p2[1].Y = yc + r;
p2[2].X = xc + r;
p2[2].Y = yc - r;
timer1->Enabled = false;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Graphics^gr=this->CreateGraphics();
SolidBrush^rb=gcnew SolidBrush(Color::Red);
SolidBrush^rb1=gcnew SolidBrush(Color::Blue);
ris(gr,rb,rb1,p1);
timer1->Enabled=true;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
Graphics^gr=this->CreateGraphics();
SolidBrush^rb=gcnew SolidBrush(Color::White);
SolidBrush^rb3=gcnew SolidBrush(Color::White);
gr->FillEllipse(rb, 0.5*r, 0.5*r, 3*r, 3*r);
rotate(p1,p2);
move(xc,yc);
rb3=gcnew SolidBrush(Color::Red);
SolidBrush^rb1=gcnew SolidBrush(Color::Blue);
ris(gr,rb,rb1,p1);
}
};
} |