Advertisement
ProgNeo

Untitled

Dec 21st, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Kursach
  12. {
  13. public partial class Form1 : Form
  14. {
  15. List<Emmiter> emmiters = new List<Emmiter>();
  16. Emmiter emmiter;
  17. List<ImpactPoint> impactPoints = new List<ImpactPoint>();
  18. Kruglishok point1; // добавил поле под первую точку
  19. Kruglishok point2;
  20. Kruglishok point3;
  21. Kruglishok point4;
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. picDisplay.Image = new Bitmap(picDisplay.Width, picDisplay.Height);
  26.  
  27. emmiter = new LinEmmiter
  28. {
  29. Width = picDisplay.Width,
  30. GravitationY = 0.25f,
  31. SpeedMin = 1,
  32. SpeedMax = 30
  33. };
  34. emmiters.Add(emmiter);
  35.  
  36.  
  37. point1 = new Kruglishok
  38. {
  39. X = picDisplay.Width / 2 + 190,
  40. Y = picDisplay.Height / 4f,
  41. color = Color.Purple
  42.  
  43. };
  44. point2 = new Kruglishok
  45. {
  46. X = picDisplay.Width / 2 - 80,
  47. Y = picDisplay.Height / 2f,
  48. color = Color.Aqua
  49. };
  50. point3 = new Kruglishok
  51. {
  52. X = picDisplay.Width / 2 + 50,
  53. Y = picDisplay.Height / 3f,
  54. color = Color.Violet
  55. };
  56. point4 = new Kruglishok
  57. {
  58. X = picDisplay.Width / 2 - 200,
  59. Y = 260 ,
  60. color = Color.Aquamarine
  61. };
  62.  
  63. // привязываем поля к эмиттеру
  64. emmiter.impactPoints.Add(point1);
  65. emmiter.impactPoints.Add(point2);
  66. emmiter.impactPoints.Add(point3);
  67. emmiter.impactPoints.Add(point4);
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75. private void timer1_Tick(object sender, EventArgs e)
  76. {
  77. emmiter.UpdateState(); // каждый тик обновляем систему
  78.  
  79. using (var g = Graphics.FromImage(picDisplay.Image))
  80. {
  81.  
  82. g.Clear(Color.Black);
  83. emmiter.Render(g); // рендерим систему
  84.  
  85. }
  86.  
  87. picDisplay.Invalidate();
  88. }
  89.  
  90. private void picDisplay_MouseMove_1(object sender, MouseEventArgs e)
  91. {
  92.  
  93.  
  94. }
  95.  
  96. private void trackBar1_Scroll(object sender, EventArgs e)
  97. {
  98. emmiter.SpeedMin = TBSpeedPart.Value;
  99. label1.Text = $"{TBSpeedPart.Value}";
  100. }
  101.  
  102. private void trackBar1_Scroll_1(object sender, EventArgs e)
  103. {
  104. foreach (var p in emmiter.impactPoints)
  105. {
  106. if (p is Kruglishok)
  107. {
  108. (p as Kruglishok).rad = trackBar1.Value;
  109. }
  110. }
  111. }
  112.  
  113. private void picDisplay_MouseClick(object sender, MouseEventArgs e)
  114. {
  115. if (e.Button == MouseButtons.Left)
  116. {
  117. emmiter.impactPoints.Add(new Kruglishok
  118. {
  119. X = e.X,
  120. Y = e.Y,
  121. color = Color.Red
  122. });
  123. }
  124. else if (e.Button == MouseButtons.Right)
  125. {
  126. foreach (var impactPoint in emmiter.impactPoints)
  127. {
  128. if (!(impactPoint is Kruglishok kruglishok)) continue;
  129. if (!(impactPoint.color == Color.Red)) continue;
  130. if (!(Math.Abs(kruglishok.X - e.X) <= kruglishok.rad) || !(Math.Abs(kruglishok.Y - e.Y) <= kruglishok.rad))
  131. continue;
  132. emmiter.impactPoints.Remove(kruglishok);
  133. break;
  134. }
  135. }
  136. }
  137.  
  138. private void trackBar2_Scroll(object sender, EventArgs e)
  139. {
  140.  
  141. point1.X = trackBar2.Value;
  142.  
  143.  
  144.  
  145.  
  146. // emmiter.X = trackBar2.Value;
  147. // label1.Text = $"{TBSpeedPart.Value}";
  148. }
  149.  
  150. private void label7_Click(object sender, EventArgs e)
  151. {
  152.  
  153. }
  154.  
  155. private void trackBar3_Scroll(object sender, EventArgs e)
  156. {
  157. point3.X = trackBar3.Value;
  158. }
  159.  
  160. private void trackBar4_Scroll(object sender, EventArgs e)
  161. {
  162. point2.X = trackBar4.Value;
  163. }
  164.  
  165. private void trackBar5_Scroll(object sender, EventArgs e)
  166. {
  167. point4.X = trackBar5.Value;
  168. }
  169.  
  170. private void button1_Click(object sender, EventArgs e)
  171. {
  172. point1.color = Color.Pink;
  173. point2.color = Color.Tomato;
  174. point3.color = Color.CadetBlue;
  175. point4.color = Color.YellowGreen;
  176. label4.Text = "Pink";
  177. label5.Text = "CadetBlue";
  178. label6.Text = "Tomato";
  179. label7.Text = "YellowGreen";
  180. }
  181.  
  182. private void button2_Click(object sender, EventArgs e)
  183. {
  184. point1.color = Color.Purple;
  185. point2.color = Color.Aqua;
  186. point3.color = Color.Violet;
  187. point4.color = Color.Aquamarine;
  188. label4.Text = "Purple";
  189. label5.Text = "Aqua";
  190. label6.Text = "Violet";
  191. label7.Text = "Aquamarine";
  192. }
  193. }
  194. }
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement