Guest User

Untitled

a guest
Jan 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. Console.SetCursorPosition(x, y);
  2.  
  3. tb.Clear();
  4. string s = "";
  5. for (int i = 0; i < mh; i++)
  6. {
  7. for (int j = 0; j < mw; j++)
  8. {
  9. s += MatrixArray[i, j];
  10. }
  11. s += "n";
  12. tb.Text += s;
  13. }
  14.  
  15. public static void MatrixStep(int width, int height, int[] y, int[] l)
  16. {
  17.  
  18. int x;
  19. thistime = !thistime;
  20.  
  21. for (x = 0; x < width; ++x)
  22. {
  23.  
  24. if (x % 11 == 10)
  25. {
  26.  
  27. if (!thistime)
  28. continue;
  29.  
  30. Console.ForegroundColor = ConsoleColor.White;
  31. }
  32. else
  33. {
  34. Console.ForegroundColor = ConsoleColor.DarkGreen;
  35. Console.SetCursorPosition(x, inBoxY(y[x] - 2 - (l[x] / 40 * 2), height));
  36. Console.Write(R);
  37. Console.ForegroundColor = ConsoleColor.Green;
  38. }
  39. Console.SetCursorPosition(x, y[x]);
  40. Console.Write(R);
  41. y[x] = inBoxY(y[x] + 1, height);
  42. Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
  43. Console.Write(' '); // Основной фоновый символ в потоке
  44. }
  45.  
  46. private void PrintMatrix(int x, int y, char r)
  47. {
  48. this.Dispatcher.Invoke((Action)(() =>
  49. {
  50. AddText(x, y, r);
  51. foreach (object myCanvasChild in cConsole.Children)
  52. {
  53. var tb = myCanvasChild as TextBlock;
  54. if (tb == null) return;
  55. var top = (double)tb.GetValue(Canvas.TopProperty);
  56. Canvas.SetTop(tb, top);
  57. }
  58. }));
  59. }
  60.  
  61. private void AddText(int x, int y, char r)
  62. {
  63. Rectangle rct = new Rectangle();
  64. rct.Fill = Brushes.Black;
  65. rct.Height = 19;
  66. rct.Width = 17;
  67. Canvas.SetTop(rct, 21 * x + 4);
  68. Canvas.SetLeft(rct, 18 * y);
  69. cConsole.Children.Add(rct);
  70.  
  71. var txt = new TextBlock
  72. {
  73. Text = r.ToString(),
  74. Foreground = tc,
  75. FontSize = 18,
  76. FontWeight = FontWeights.Bold,
  77. FontFamily = new FontFamily("Courier New")
  78. };
  79. Canvas.SetTop(txt, 21 * x + 5);
  80. Canvas.SetLeft(txt, 18 * y + 3);
  81. cConsole.Children.Add(txt);
  82. }
  83.  
  84. using System;
  85. using System.Threading;
  86. using System.Threading.Tasks;
  87. using System.Windows;
  88. using System.Windows.Controls;
  89. using System.Windows.Media;
  90.  
  91. namespace matrix
  92. {
  93. /// <summary>
  94. /// Interaction logic for MainWindow.xaml
  95. /// </summary>
  96. public partial class MainWindow : Window
  97. {
  98. private readonly Random rnd = new Random();
  99.  
  100. public MainWindow()
  101. {
  102. InitializeComponent();
  103. Task.Factory.StartNew(()=>
  104. {
  105. while (true)
  106. {
  107. Application.Current.Dispatcher.Invoke(()=>
  108. {
  109. AddText();
  110. foreach (object myCanvasChild in MyCanvas.Children)
  111. {
  112. var tb = myCanvasChild as TextBlock;
  113. if (tb == null) return;
  114. var top = (double) tb.GetValue(Canvas.TopProperty);
  115. Canvas.SetTop(tb, top + 50);
  116. }
  117. });
  118. Thread.Sleep(TimeSpan.FromMilliseconds(300));
  119. }
  120. });
  121. }
  122.  
  123. private void AddText()
  124. {
  125. var txt = new TextBlock
  126. {
  127. Text = $"some message value ={rnd.Next()}",
  128. Foreground = new SolidColorBrush(Colors.Green)
  129. };
  130. Canvas.SetTop(txt, 0);
  131. MyCanvas.Children.Add(txt);
  132. }
  133. }
  134. }
  135.  
  136. <Window x:Class="matrix.MainWindow"
  137. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  138. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  139. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  140. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  141. mc:Ignorable="d"
  142. Title="MainWindow" Height="350" Width="525">
  143. <Canvas Name="MyCanvas">
  144.  
  145. </Canvas>
Add Comment
Please, Sign In to add comment