Форум программистов, компьютерный форум, киберфорум
C++/CLI Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.54/13: Рейтинг темы: голосов - 13, средняя оценка - 4.54
0 / 0 / 0
Регистрация: 29.07.2015
Сообщений: 8
1

Анимация движения круга

21.05.2017, 00:23. Показов 2478. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте!
Мне нужно чтобы по круговой рамке по и против часовой стрелки двигался круг. Как можно этот треугольник заменить на круг?

C++
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);
    }
};
}
Если 211 строчку заменить на
C++
1
gr->FillEllipse(rb1, 0.65*r, r, r, r);
то получается круг, но ничего не двигается. Как его заставить двигаться по и против часовой стрелки?
Миниатюры
Анимация движения круга  
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
21.05.2017, 00:23
Ответы с готовыми решениями:

Анимация перемещение круга по прямой(условно) в зависимости от заданных координат
Итак, написал программу, но она не работает так, как от меня требуют. Должно быть: &quot;Считать...

Написать програму для движения мерцающего круга по эллипсу (анимация движения)
Добрый день,передо мной стоит задача : Написать програму для движения мерцающего круга по...

Анимация круга.
Здравствуйте, Помогите пожалуйста. Сделать нужно красный залитый круг радиусом пикселей 30 что бы...

Движения круга и прямоугольника в круге
Здравствуйте,мне нужна помощь. Решил сделать программу в которой при нажатии на стрелки,круг и...

1
0 / 0 / 0
Регистрация: 29.07.2015
Сообщений: 8
21.05.2017, 23:49  [ТС] 2
Как уменьшить радиус движения красного круга?
C++
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
#pragma once
#define _USE_MATH_DEFINES
#include <math.h>
 
 
namespace WA1 {
 
    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^  button2;
    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>
        /// Требуется переменная конструктора.
        float x, y,dx,dy;
        float r;
        int xmin, ymin, xmax, ymax;
        Graphics ^im;                       
    
        public:
void RotateTransformAngle (PaintEventArgs^ e)
{
    float angle;
}
 
        void ReDraw()
        {
            
            SolidBrush ^brf=gcnew SolidBrush (Color::White);
            Pen ^pnf=gcnew Pen(Color::Black);
                im->FillEllipse(brf, r, r, 15 * r, 15 * r);
                 im->DrawEllipse(pnf, r, r, 15 * r, 15 * r);
        }
        void DrawFig()
        {
            SolidBrush ^brf=gcnew SolidBrush (Color::Red);
            im->FillEllipse(brf, 11.2*r, r*11.2, 3*r, 3*r);
        }
        /// </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->button2 = (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->Location = System::Drawing::Point(411, 149);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(84, 31);
            this->button1->TabIndex = 0;
            this->button1->Text = L"Ввод";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(411, 186);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(84, 31);
            this->button2->TabIndex = 1;
            this->button2->Text = L"Рисовать";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(411, 223);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(84, 31);
            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(411, 98);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(100, 20);
            this->textBox1->TabIndex = 3;
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(408, 82);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(72, 13);
            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(537, 355);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            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) {
             }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
              r=Convert::ToDouble(textBox1->Text);
         }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
            xmin=30;
            ymin=30;
            xmax=this->Width-300;
            ymax=this->Height-300;
            im=CreateGraphics();
            x=xmin+70;
            float tg=(float)(ymax-ymin)/(xmax-xmin);
            y=ymin+(x-xmin)*tg;
            dx=1;
            dy=dx*tg;
            ReDraw();
            DrawFig();
         }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
 
             timer1->Enabled=!(timer1->Enabled);
         }
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
            DrawFig();
            int r;
            int angle;
            x=r*Math::Cos(angle)-(Height/2);
            y=r*Math::Sin(angle)-(Width/2);
            angle -= 5;
            im->RotateTransform (angle);
            
         }
         
};
}
0
21.05.2017, 23:49
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
21.05.2017, 23:49
Помогаю со студенческими работами здесь

Динамика движения круга по параболе
динамика движения круга по параболе y=x*x

Задать ограничения для движения круга
вот код программы: program dvigai_krug_2; uses crt,GraphABC; var a: string; var x,y,r,b,c:...

Составьте программу для описания движения круга
Работа с графикой. 8. Составьте программу для описания движения круга.

Анимация движения
import java.awt.Color; import java.util.EventObject; import java.awt.Dimension; import...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru