-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMatrix.cs
89 lines (81 loc) · 2.33 KB
/
Matrix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Windows;
using System.Windows.Controls;
namespace MatrixGraphicsGenerator
{
public class Matrix : MatrixBase
{
public Matrix(Tuple<int, int> matrixSize, Grid grid, TextBox codeTextBox, Button codeButton, TextBox nameTextBox) :
base (matrixSize, grid, codeTextBox, codeButton, nameTextBox) { }
/// <summary>
/// Shifts the matrix horizontally
/// </summary>
public void ShiftHorizontally(bool shiftRight)
{
foreach (MatrixRow row in rows)
{
if (shiftRight)
row.Code >>= 1;
else
row.Code <<= 1;
}
UpdateCode(currentType, false);
}
/// <summary>
/// Shifts the matrix vertically
/// </summary>
public void ShiftVertically(bool shiftUpwards)
{
if (shiftUpwards)
{
// Iterate forwards
for (int i = 0; i < rows.Length; i++)
{
if (i + 1 == rows.Length)
rows[i].Code = 0;
else
rows[i].Code = rows[i + 1].Code;
}
}
else
{
// Iterate backwards
for (int i = rows.Length - 1; i >= 0; i--)
{
if (i == 0)
rows[i].Code = 0;
else
rows[i].Code = rows[i - 1].Code;
}
}
}
/// <summary>
/// Inverts all of the LEDs
/// </summary>
public void InvertAll()
{
foreach (MatrixRow row in rows)
{
foreach (LED led in row.LEDs)
{
led.Enabled = !led.Enabled;
}
}
UpdateCode(currentType, true);
}
/// <summary>
/// Sets all of the LEDs to a state
/// </summary>
public void SetAll(bool state)
{
foreach (MatrixRow row in rows)
{
foreach (LED led in row.LEDs)
{
led.Enabled = state;
}
}
UpdateCode(currentType, true);
}
}
}