Advertisement
Tevronis

sht

Nov 6th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace ProjectForm {
  4.  
  5. using namespace System;
  6. using namespace System::ComponentModel;
  7. using namespace System::Collections;
  8. using namespace System::Windows::Forms;
  9. using namespace System::Data;
  10. using namespace System::Drawing;
  11.  
  12. public ref class MyForm : public System::Windows::Forms::Form
  13. {
  14. public:
  15. MyForm(void){
  16. InitializeComponent();
  17. Wcx = 60, Wcy = 240, Wx = 300, Wy = 200;
  18. goX = Wx * g_lines / Vx;
  19. goY = Wy * v_lines / Vy;
  20.  
  21. }
  22.  
  23. protected:
  24. ~MyForm()
  25. {
  26. if (components)
  27. {
  28. delete components;
  29. }
  30. }
  31.  
  32. private:
  33. System::ComponentModel::Container ^components;
  34. float Wcx, Wcy, Wx, Wy;
  35. float goX;
  36. float goY;
  37. #pragma region Windows Form Designer generated code
  38.  
  39. void InitializeComponent(void)
  40. {
  41. this->SuspendLayout();
  42.  
  43. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  44. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  45. this->ClientSize = System::Drawing::Size(397, 288);
  46. this->Name = L"MyForm";
  47. this->Text = L"MyForm";
  48. this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  49. this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
  50. this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
  51. this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
  52. this->ResumeLayout(false);
  53.  
  54. }
  55. #pragma endregion
  56. private: System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e) {
  57.  
  58. Rectangle rect = Form::ClientRectangle;
  59. goX *= (rect.Width - left - right) / Wx;
  60. goY *= (rect.Height - bottom - top) / Wy ;
  61. Wcx = left;
  62. Wcy = rect.Height - bottom;
  63. Wx = rect.Width - left - right;
  64. Wy = rect.Height - bottom - top;
  65.  
  66. this->Refresh();
  67. }
  68.  
  69. private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
  70. Graphics^ g = e->Graphics;
  71. g->Clear(Color::LightGreen);
  72. Pen^ blackPen = gcnew Pen(Color::Black);
  73. blackPen->Width = 2;
  74. Pen^ greenPen = gcnew Pen(Color::Blue);
  75. greenPen->Width = 2;
  76. Pen^ newPen = gcnew Pen(Color::Blue);
  77. newPen->Width = 1;
  78. System::Drawing::Font^ drawFont = gcnew System::Drawing::Font("Arial", 8);
  79. SolidBrush^ drawBrush = gcnew SolidBrush(Color::Red);
  80. Rectangle rect = Form::ClientRectangle;
  81. g->DrawLine(blackPen, Wcx, Wcy, Wcx + Wx, Wcy);
  82. g->DrawLine(blackPen, Wcx + Wx, Wcy, Wcx + Wx, Wcy - Wy);
  83. g->DrawLine(blackPen, Wcx + Wx, Wcy - Wy, Wcx, Wcy - Wy);
  84. g->DrawLine(blackPen, Wcx, Wcy - Wy, Wcx, Wcy);
  85.  
  86.  
  87. point minP, maxP;
  88. minP.x = Wcx + 1; minP.y = Wcy - Wy;
  89. maxP.x = Wcx + Wx; maxP.y = Wcy;
  90.  
  91. for (float i = Wcy - Wy / 2; i < Wcy; i += goY)
  92. {
  93. g->DrawLine(newPen, Wcx, i, Wcx + Wx, i);
  94. g->DrawLine(newPen, Wcx, 2 * Wcy - Wy - i, Wcx + Wx, 2 * Wcy - Wy - i);
  95. double Check = Vcy - Vy * (2 * Wcy - Wy - i - Wcy) / Wy;
  96. double y1 = Vcy - Vy * (i - Wcy) / Wy;
  97. System::String ^ y_sim = System::Convert::ToString(Check);
  98. if (y_sim->Length > 5)
  99. y_sim = y_sim->Remove(5);
  100. g->DrawString(y_sim, drawFont, drawBrush, Wcx - 30, 2 * Wcy - Wy - i);
  101. if (Check == y1)
  102. continue;
  103. y_sim = System::Convert::ToString(y1);
  104. if (y_sim->Length > 5)
  105. y_sim = y_sim->Remove(5);
  106. g->DrawString(y_sim, drawFont, drawBrush, Wcx - 35, i);
  107. }
  108.  
  109. for (float i = Wcx + Wx / 2; i < Wcx + Wx; i += goX)
  110. {
  111. g->DrawLine(newPen, i, Wcy - Wy, i, Wcy);
  112. g->DrawLine(newPen, 2 * Wcx + Wx - i, Wcy - Wy, 2 * Wcx + Wx - i, Wcy);
  113. double Check = Vcx + Vx * (i - Wcx) / Wx;
  114. double x1 = Vcx + Vx * (2 * Wcx + Wx - i - Wcx) / Wx;
  115. System::String ^ x_sim = System::Convert::ToString(Check);
  116. if (x_sim->Length > 5)
  117. x_sim = x_sim->Remove(5);
  118. g->DrawString(x_sim, drawFont, drawBrush, i - 5, Wcy - Wy - 15);
  119. x_sim = System::Convert::ToString(x1);
  120. if (Check == x1)
  121. continue;
  122. if (x_sim->Length > 5)
  123. x_sim = x_sim->Remove(5);
  124. g->DrawString(x_sim, drawFont, drawBrush, 2 * Wcx + Wx - i - 5, Wcy - Wy - 15);
  125. }
  126.  
  127. float x1 = Wcx, x = Vcx;
  128. bool visible1, visible2;
  129. float y, y1, y2;
  130. if (fexists(x)) {
  131. visible1 = true;
  132. y = f(x);
  133. y1 = Wcy - Wy * (y - Vcy) / Vy;
  134. }
  135. else
  136. visible1 = false;
  137.  
  138. while (x1 < Wcx + Wx) {
  139. x = (x1 + 1 - Wcx) * Vx / Wx + Vcx;
  140. if (fexists(x)) {
  141. visible2 = true;
  142. y = f(x);
  143. y2 = Wcy - Wy * (y - Vcy) / Vy;
  144. }
  145. else
  146. visible2 = false;
  147.  
  148. if (visible1 && visible2) {
  149. if (Vx != 0) {
  150. point a, b;
  151. a.x = x1;
  152. a.y = y1;
  153. b.x = x1 + 1;
  154. b.y = y2;
  155. if (clip(a, b, minP, maxP)) {
  156. g->DrawLine(blackPen, a.x, a.y, b.x, b.y);
  157. }
  158. }
  159. }
  160. x1 = x1 + 1;
  161. y1 = y2;
  162. visible1 = visible2;
  163. }
  164. }
  165.  
  166. private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
  167. Rectangle rect = Form::ClientRectangle;
  168. left = Wcx;
  169. bottom = rect.Height - Wcy;
  170. right = rect.Width - Wcx - Wx;
  171. top = Wcy - Wy;
  172.  
  173. }
  174.  
  175. private: System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
  176. float dMove = 40, dScale = 4;
  177. float di;
  178. switch (e->KeyCode){
  179. case Keys::W:
  180. Vcy -= Vy / dMove/30;
  181. break;
  182. case Keys::S:
  183. Vcy += Vy / dMove/30;
  184. break;
  185. case Keys::A:
  186. Vcx += Vx / dMove / 30;
  187. break;
  188. case Keys::D:
  189. Vcx -= Vx / dMove/30;
  190. break;
  191.  
  192. case Keys::T:
  193. Vcy -= (5 * (Vy / dMove/30));
  194. break;
  195. case Keys::G:
  196. Vcy += (5 * (Vy / dMove/30));
  197. break;
  198. case Keys::F:
  199. Vcx += (5 * (Vx / dMove/30));
  200. break;
  201. case Keys::H:
  202. Vcx -= (5 * (Vx / dMove/30));
  203. break;
  204. case Keys::I:
  205. di = Vcy + Vy / 2;
  206. Vy -= Vy / dScale;
  207. Vcy = di - Vy / 2;
  208. break;
  209. case Keys::K:
  210. di = Vcy + Vy / 2;
  211. Vy += Vy / dScale;
  212. Vcy = di - Vy / 2;
  213. break;
  214. case Keys::O:
  215. di = Vcx + Vx / 2;
  216. Vx += Vx / dScale;
  217. Vcx = di - Vx / 2;
  218. break;
  219. case Keys::L:
  220. di = Vcx + Vx / 2;
  221. Vx -= Vx / dScale;
  222. Vcx = di - Vx / 2;
  223. break;
  224.  
  225. case Keys::Q:
  226. if (goY < Wy/2) goY *= 2;
  227. break;
  228. case Keys::E:
  229. if (goY > 15) goY /= 2;
  230. break;
  231. case Keys::Z:
  232. if (goX < Wx/2) goX *= 2;
  233. break;
  234. case Keys::C:
  235. if (goX > 15) goX /= 2;
  236. break;
  237.  
  238. case Keys::Escape:
  239. Vcx = -15; Vcy = -1.5; Vx = 30; Vy = 3;
  240. goX = 30; goY = 30; v_lines = 0.7; g_lines = 4;
  241. break;
  242. default:;
  243. }
  244. this->Refresh();
  245. }
  246. };
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement