Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace ProjectForm {
- 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 MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void){
- InitializeComponent();
- Wcx = 60, Wcy = 240, Wx = 300, Wy = 200;
- goX = Wx * g_lines / Vx;
- goY = Wy * v_lines / Vy;
- }
- protected:
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private:
- System::ComponentModel::Container ^components;
- float Wcx, Wcy, Wx, Wy;
- float goX;
- float goY;
- #pragma region Windows Form Designer generated code
- void InitializeComponent(void)
- {
- this->SuspendLayout();
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(397, 288);
- this->Name = L"MyForm";
- this->Text = L"MyForm";
- this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
- this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
- this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
- this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
- this->ResumeLayout(false);
- }
- #pragma endregion
- private: System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e) {
- Rectangle rect = Form::ClientRectangle;
- goX *= (rect.Width - left - right) / Wx;
- goY *= (rect.Height - bottom - top) / Wy ;
- Wcx = left;
- Wcy = rect.Height - bottom;
- Wx = rect.Width - left - right;
- Wy = rect.Height - bottom - top;
- this->Refresh();
- }
- private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
- Graphics^ g = e->Graphics;
- g->Clear(Color::LightGreen);
- Pen^ blackPen = gcnew Pen(Color::Black);
- blackPen->Width = 2;
- Pen^ greenPen = gcnew Pen(Color::Blue);
- greenPen->Width = 2;
- Pen^ newPen = gcnew Pen(Color::Blue);
- newPen->Width = 1;
- System::Drawing::Font^ drawFont = gcnew System::Drawing::Font("Arial", 8);
- SolidBrush^ drawBrush = gcnew SolidBrush(Color::Red);
- Rectangle rect = Form::ClientRectangle;
- g->DrawLine(blackPen, Wcx, Wcy, Wcx + Wx, Wcy);
- g->DrawLine(blackPen, Wcx + Wx, Wcy, Wcx + Wx, Wcy - Wy);
- g->DrawLine(blackPen, Wcx + Wx, Wcy - Wy, Wcx, Wcy - Wy);
- g->DrawLine(blackPen, Wcx, Wcy - Wy, Wcx, Wcy);
- point minP, maxP;
- minP.x = Wcx + 1; minP.y = Wcy - Wy;
- maxP.x = Wcx + Wx; maxP.y = Wcy;
- for (float i = Wcy - Wy / 2; i < Wcy; i += goY)
- {
- g->DrawLine(newPen, Wcx, i, Wcx + Wx, i);
- g->DrawLine(newPen, Wcx, 2 * Wcy - Wy - i, Wcx + Wx, 2 * Wcy - Wy - i);
- double Check = Vcy - Vy * (2 * Wcy - Wy - i - Wcy) / Wy;
- double y1 = Vcy - Vy * (i - Wcy) / Wy;
- System::String ^ y_sim = System::Convert::ToString(Check);
- if (y_sim->Length > 5)
- y_sim = y_sim->Remove(5);
- g->DrawString(y_sim, drawFont, drawBrush, Wcx - 30, 2 * Wcy - Wy - i);
- if (Check == y1)
- continue;
- y_sim = System::Convert::ToString(y1);
- if (y_sim->Length > 5)
- y_sim = y_sim->Remove(5);
- g->DrawString(y_sim, drawFont, drawBrush, Wcx - 35, i);
- }
- for (float i = Wcx + Wx / 2; i < Wcx + Wx; i += goX)
- {
- g->DrawLine(newPen, i, Wcy - Wy, i, Wcy);
- g->DrawLine(newPen, 2 * Wcx + Wx - i, Wcy - Wy, 2 * Wcx + Wx - i, Wcy);
- double Check = Vcx + Vx * (i - Wcx) / Wx;
- double x1 = Vcx + Vx * (2 * Wcx + Wx - i - Wcx) / Wx;
- System::String ^ x_sim = System::Convert::ToString(Check);
- if (x_sim->Length > 5)
- x_sim = x_sim->Remove(5);
- g->DrawString(x_sim, drawFont, drawBrush, i - 5, Wcy - Wy - 15);
- x_sim = System::Convert::ToString(x1);
- if (Check == x1)
- continue;
- if (x_sim->Length > 5)
- x_sim = x_sim->Remove(5);
- g->DrawString(x_sim, drawFont, drawBrush, 2 * Wcx + Wx - i - 5, Wcy - Wy - 15);
- }
- float x1 = Wcx, x = Vcx;
- bool visible1, visible2;
- float y, y1, y2;
- if (fexists(x)) {
- visible1 = true;
- y = f(x);
- y1 = Wcy - Wy * (y - Vcy) / Vy;
- }
- else
- visible1 = false;
- while (x1 < Wcx + Wx) {
- x = (x1 + 1 - Wcx) * Vx / Wx + Vcx;
- if (fexists(x)) {
- visible2 = true;
- y = f(x);
- y2 = Wcy - Wy * (y - Vcy) / Vy;
- }
- else
- visible2 = false;
- if (visible1 && visible2) {
- if (Vx != 0) {
- point a, b;
- a.x = x1;
- a.y = y1;
- b.x = x1 + 1;
- b.y = y2;
- if (clip(a, b, minP, maxP)) {
- g->DrawLine(blackPen, a.x, a.y, b.x, b.y);
- }
- }
- }
- x1 = x1 + 1;
- y1 = y2;
- visible1 = visible2;
- }
- }
- private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
- Rectangle rect = Form::ClientRectangle;
- left = Wcx;
- bottom = rect.Height - Wcy;
- right = rect.Width - Wcx - Wx;
- top = Wcy - Wy;
- }
- private: System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
- float dMove = 40, dScale = 4;
- float di;
- switch (e->KeyCode){
- case Keys::W:
- Vcy -= Vy / dMove/30;
- break;
- case Keys::S:
- Vcy += Vy / dMove/30;
- break;
- case Keys::A:
- Vcx += Vx / dMove / 30;
- break;
- case Keys::D:
- Vcx -= Vx / dMove/30;
- break;
- case Keys::T:
- Vcy -= (5 * (Vy / dMove/30));
- break;
- case Keys::G:
- Vcy += (5 * (Vy / dMove/30));
- break;
- case Keys::F:
- Vcx += (5 * (Vx / dMove/30));
- break;
- case Keys::H:
- Vcx -= (5 * (Vx / dMove/30));
- break;
- case Keys::I:
- di = Vcy + Vy / 2;
- Vy -= Vy / dScale;
- Vcy = di - Vy / 2;
- break;
- case Keys::K:
- di = Vcy + Vy / 2;
- Vy += Vy / dScale;
- Vcy = di - Vy / 2;
- break;
- case Keys::O:
- di = Vcx + Vx / 2;
- Vx += Vx / dScale;
- Vcx = di - Vx / 2;
- break;
- case Keys::L:
- di = Vcx + Vx / 2;
- Vx -= Vx / dScale;
- Vcx = di - Vx / 2;
- break;
- case Keys::Q:
- if (goY < Wy/2) goY *= 2;
- break;
- case Keys::E:
- if (goY > 15) goY /= 2;
- break;
- case Keys::Z:
- if (goX < Wx/2) goX *= 2;
- break;
- case Keys::C:
- if (goX > 15) goX /= 2;
- break;
- case Keys::Escape:
- Vcx = -15; Vcy = -1.5; Vx = 30; Vy = 3;
- goX = 30; goY = 30; v_lines = 0.7; g_lines = 4;
- break;
- default:;
- }
- this->Refresh();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement