Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media;
  5. using System.Windows.Media.Imaging;
  6.  
  7. namespace KG
  8. {
  9. public class Point
  10. {
  11. public int X { get; set; }
  12. public int Y { get; set; }
  13. }
  14.  
  15. public class Lines : Point
  16. {
  17. public int Xstart { get; set; }
  18. public int Ystart { get; set; }
  19. public int Xend { get; set; }
  20. public int Yend { get; set; }
  21. }
  22.  
  23. /// <summary>
  24. /// Логика взаимодействия для LR1.xaml
  25. /// </summary>
  26. public partial class Lr2
  27. {
  28. public int CountHorisontal;
  29. public int CountVertical;
  30.  
  31. public int IdLabel;
  32. public int SizeX;
  33. public int SizeY;
  34.  
  35. public Lr2()
  36. {
  37. InitializeComponent();
  38. Background = new SolidColorBrush(Color.FromRgb(30, 30, 30));
  39. }
  40.  
  41. private void CreateLabel(int i, int j, string z)
  42. {
  43. IdLabel++;
  44. var dynamicLabel = new Label
  45. {
  46. Name = "label" + IdLabel,
  47. Content = z,
  48. FontSize = 10,
  49. FontFamily = new FontFamily("Times New Roman"),
  50. Margin = new Thickness(i, j, 0, 0),
  51. Foreground = new SolidColorBrush(Colors.White)
  52. };
  53. if ((string) dynamicLabel.Content == "0" || (string) dynamicLabel.Content == "-0") return;
  54. Grid.Children.Add(dynamicLabel);
  55. }
  56.  
  57. private void CreateImage(int moveHorisontal, int moveVertical, int sizeX, int sizeY)
  58. {
  59. SizeX += sizeX;
  60. SizeY += sizeY;
  61.  
  62. var wb = new WriteableBitmap((int) Img.Width, (int) Img.Height, 200, 200, PixelFormats.Bgra32, null);
  63. const int stride = 200;
  64. const int alpha = 255;
  65. var blue = 255;
  66. var red = 255;
  67. var green = 255;
  68. Int32Rect rect;
  69.  
  70. byte[] blackColorData = {(byte) blue, (byte) green, (byte) red, alpha};
  71.  
  72. for (var i = 0; i < 550; i++)
  73. {
  74. var horisontal = new Int32Rect(i, 175, 1, 1);
  75. wb.WritePixels(horisontal, blackColorData, stride, 0);
  76. if (i % 35 != 0) continue;
  77. CreateLabel(235 + i, 175 + 5, "" + i);
  78. CreateLabel(235 - i, 175 + 5, "-" + i);
  79. for (var j = 0; j < 5; j++)
  80. {
  81. var dashTop = new Int32Rect(i, 175 - j, 1, 1);
  82. wb.WritePixels(dashTop, blackColorData, stride, 0);
  83. var dashDown = new Int32Rect(i, 175 + j, 1, 1);
  84. wb.WritePixels(dashDown, blackColorData, stride, 0);
  85. }
  86. }
  87.  
  88. for (var i = 0; i < 340; i++)
  89. {
  90. var vertical = new Int32Rect(245, i, 1, 1);
  91. wb.WritePixels(vertical, blackColorData, stride, 0);
  92. if (i % 35 != 0) continue;
  93. CreateLabel(245 + 5, 165 - i, "" + i);
  94. CreateLabel(245 + 5, 165 + i, "-" + i);
  95. for (var j = 0; j < 5; j++)
  96. {
  97. var dashLeft = new Int32Rect(245 - j, i, 1, 1);
  98. wb.WritePixels(dashLeft, blackColorData, stride, 0);
  99. var dashRight = new Int32Rect(245 + j, i, 1, 1);
  100. wb.WritePixels(dashRight, blackColorData, stride, 0);
  101. }
  102. }
  103.  
  104. var a = new Point {X = 300 - SizeX, Y = 100 - SizeY};
  105. var b = new Point {X = 500 + SizeX, Y = 100 - SizeY};
  106. var c = new Point {X = 300 - SizeX, Y = 300 + SizeY};
  107. var d = new Point {X = 500 + SizeX, Y = 300 + SizeY};
  108.  
  109. var firstLine = new Lines
  110. {
  111. Xstart = a.X + moveHorisontal,
  112. Ystart = a.Y + moveVertical,
  113. Xend = b.X + moveHorisontal,
  114. Yend = b.Y + moveVertical
  115. };
  116.  
  117. var secondLine = new Lines
  118. {
  119. Xstart = a.X + moveHorisontal,
  120. Ystart = a.Y + moveVertical,
  121. Xend = c.X + moveHorisontal,
  122. Yend = c.Y + moveVertical
  123. };
  124.  
  125. var thirdLine = new Lines
  126. {
  127. Xstart = c.X + moveHorisontal,
  128. Ystart = c.Y + moveVertical,
  129. Xend = d.X + moveHorisontal,
  130. Yend = d.Y + moveVertical
  131. };
  132.  
  133. var fourthLine = new Lines
  134. {
  135. Xstart = b.X + moveHorisontal,
  136. Ystart = b.Y + moveVertical,
  137. Xend = d.X + moveHorisontal,
  138. Yend = d.Y + moveVertical
  139. };
  140.  
  141. // Линия 1
  142. var n = Math.Max(Math.Abs(firstLine.Xend - firstLine.Xstart), Math.Abs(firstLine.Yend - firstLine.Ystart));
  143.  
  144. var xA = new int[n];
  145. var yA = new int[n];
  146. xA[0] = firstLine.Xstart;
  147. yA[0] = firstLine.Ystart;
  148. for (var i = 1; i < n; i++)
  149. {
  150. xA[i] = xA[i - 1] + (firstLine.Xend - firstLine.Xstart) / n;
  151. yA[i] = yA[i - 1] + (firstLine.Yend - firstLine.Ystart) / n;
  152. }
  153.  
  154. for (var i = 0; i < n; i++)
  155. {
  156. red = 155 + i;
  157. blue = 100;
  158. green = 100;
  159. byte[] colorData = {(byte) blue, (byte) green, (byte) red, alpha};
  160. rect = new Int32Rect(xA[i], yA[i], 1, 1);
  161. wb.WritePixels(rect, colorData, stride, 0);
  162. }
  163.  
  164. // Линия 2
  165. n = Math.Max(Math.Abs(secondLine.Xend - secondLine.Xstart), Math.Abs(secondLine.Yend - secondLine.Ystart));
  166. var xB = new int[n];
  167. var yB = new int[n];
  168. xB[0] = secondLine.Xstart;
  169. yB[0] = secondLine.Ystart;
  170.  
  171. for (var i = 1; i < n; i++)
  172. {
  173. xB[i] = xB[i - 1] + (secondLine.Xend - secondLine.Xstart) / n;
  174. yB[i] = yB[i - 1] + (secondLine.Yend - secondLine.Ystart) / n;
  175. }
  176.  
  177. for (var i = 0; i < n; i++)
  178. {
  179. red = 155 + i;
  180. blue = 100;
  181. green = 100 + i;
  182. byte[] colorData = {(byte) blue, (byte) green, (byte) red, alpha};
  183. rect = new Int32Rect(xB[i], yB[i], 1, 1);
  184. wb.WritePixels(rect, colorData, stride, 0);
  185. }
  186.  
  187. // Линия 3
  188. n = Math.Max(Math.Abs(thirdLine.Xend - thirdLine.Xstart), Math.Abs(thirdLine.Yend - thirdLine.Ystart));
  189. var xC = new int[n];
  190. var yC = new int[n];
  191. xC[0] = thirdLine.Xstart;
  192. yC[0] = thirdLine.Ystart;
  193.  
  194. for (var i = 1; i < n; i++)
  195. {
  196. xC[i] = xC[i - 1] + (thirdLine.Xend - thirdLine.Xstart) / n;
  197. yC[i] = yC[i - 1] + (thirdLine.Yend - thirdLine.Ystart) / n;
  198. }
  199.  
  200. for (var i = 0; i < n; i++)
  201. {
  202. red = 155;
  203. blue = 100;
  204. green = 100 + i;
  205. byte[] colorData = {(byte) blue, (byte) green, (byte) red, alpha};
  206. rect = new Int32Rect(xC[i], yC[i], 1, 1);
  207. wb.WritePixels(rect, colorData, stride, 0);
  208. }
  209.  
  210. // Линия 4
  211. n = Math.Max(Math.Abs(fourthLine.Xend - fourthLine.Xstart), Math.Abs(fourthLine.Yend - fourthLine.Ystart));
  212. var xD = new int[n];
  213. var yD = new int[n];
  214. xD[0] = fourthLine.Xstart;
  215. yD[0] = fourthLine.Ystart;
  216.  
  217. for (var i = 1; i < n; i++)
  218. {
  219. xD[i] = xD[i - 1] + (fourthLine.Xend - fourthLine.Xstart) / n;
  220. yD[i] = yD[i - 1] + (fourthLine.Yend - fourthLine.Ystart) / n;
  221. }
  222.  
  223. for (var i = 0; i < n; i++)
  224. {
  225. red = 155 + i;
  226. blue = 100;
  227. green = 100 + i;
  228. byte[] colorData = {(byte) blue, (byte) green, (byte) red, alpha};
  229. rect = new Int32Rect(xD[i], yD[i], 1, 1);
  230. wb.WritePixels(rect, colorData, stride, 0);
  231. }
  232. Img.Source = wb;
  233. }
  234.  
  235. private void CreatePicure(object sender, RoutedEventArgs e)
  236. {
  237. CountHorisontal = -155;
  238. CountVertical = -27;
  239. CreateImage(CountHorisontal, CountVertical, 0, 0);
  240. }
  241.  
  242. private void Left_Click(object sender, RoutedEventArgs e)
  243. {
  244. CountHorisontal -= 35;
  245. CreateImage(CountHorisontal, CountVertical, 0, 0);
  246. }
  247.  
  248. private void Right_Click(object sender, RoutedEventArgs e)
  249. {
  250. CountHorisontal += 35;
  251. CreateImage(CountHorisontal, CountVertical, 0, 0);
  252. }
  253.  
  254. private void Down_Click(object sender, RoutedEventArgs e)
  255. {
  256. CountVertical += 35;
  257. CreateImage(CountHorisontal, CountVertical, 0, 0);
  258. }
  259.  
  260. private void Top_Click(object sender, RoutedEventArgs e)
  261. {
  262. CountVertical -= 35;
  263. CreateImage(CountHorisontal, CountVertical, 0, 0);
  264. }
  265.  
  266. private void Increase_Click(object sender, RoutedEventArgs e)
  267. {
  268. CreateImage(CountHorisontal, CountVertical, 10, 10);
  269. }
  270.  
  271. private void reduce_Click(object sender, RoutedEventArgs e)
  272. {
  273. CreateImage(CountHorisontal, CountVertical, -10, -10);
  274. }
  275. }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement