forked from bracci/Qlockthree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transitions.cpp
153 lines (140 loc) · 3.9 KB
/
Transitions.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
Transitions.cpp
Transitionen bei Wechsel Zeitmatrix
@mc Arduino/UNO
@autor Manuel Bracher / [email protected]
@version 1.0
@created 19.05.15
*/
#include "Transitions.h"
#include "Debug.h"
byte Transitions::_counter;
word Transitions::_usedColumns;
byte Transitions::_remainingCoulumnCount;
boolean Transitions::_ereasingDone;
boolean Transitions::_writingDone;
void Transitions::resetTransition () {
_counter = 0;
_usedColumns = 0;
_remainingCoulumnCount = 12;
_ereasingDone = false;
_writingDone = false;
}
boolean Transitions::nextSlideStep (word matrixNew[16], word matrix[16]) {
_counter++;
if (_counter < 22) {
for (byte i = 0; i < min( _counter, 12); i++) {
shiftColumnDown(matrixNew, i);
}
}
else {
for (byte i = max(_counter - 22 - 9, 0); i < min( _counter - 21, 12); i++) {
shiftColumnUp(matrixNew, matrix, i);
}
}
return (_counter > 41);
}
void Transitions::shiftColumnDown (word matrix[16], byte column) {
word tempMatrix = (0x01 << (15 - column));
for (byte i = 10; i > 0; i--) {
matrix[i] &= ~tempMatrix;
matrix[i] |= (matrix[i - 1] & tempMatrix);
}
matrix[0] &= ~tempMatrix;
}
void Transitions::shiftColumnUp (word matrixNew[16], word matrix[16], byte column) {
word tempMatrix = (0x01 << (15 - column));
byte tempIdx;
for (byte i = 0; i < 10; i++) {
matrixNew[i] &= ~tempMatrix;
tempIdx = i - (9 + column - (_counter - 22));
if (tempIdx < 12) {
matrixNew[i] |= (matrix[tempIdx] & tempMatrix);
}
}
matrix[10] &= ~tempMatrix;
}
boolean Transitions::nextMatrixStep(word matrixWeak[16], word matrixTime[16], word matrixMatrix[16], word matrix[16]) {
byte loopCount = random(0, 5);
byte column;
if (!_ereasingDone) {
shiftDownMatrixErease(matrixMatrix, matrixWeak);
if (random(0, 3) > 0)
{
if ((_remainingCoulumnCount < 3) && (_remainingCoulumnCount > 0))
{
matrixMatrix[0] |= ~_usedColumns;
_usedColumns |= matrixMatrix[0];
_remainingCoulumnCount = 0;
}
else
{
for ( byte i = 0; i < loopCount; i++) {
column = random(4, 16);
if (!(_usedColumns & (0x01 << column))) {
_usedColumns |= (0x01 << column);
_remainingCoulumnCount--;
}
matrixMatrix[0] |= 0x01 << column;
}
}
}
}
else {
shiftDownMatrixWrite(matrixMatrix, matrixWeak);
if ((random(0, 3) > 0) && (_remainingCoulumnCount > 0))
{
if (_remainingCoulumnCount < 3)
{
matrixMatrix[0] |= ~_usedColumns;
_usedColumns |= matrixMatrix[0];
_remainingCoulumnCount = 0;
}
else
{
for ( byte i = 0; i < loopCount; i++) {
column = random(4, 16);
if (!(_usedColumns & (0x01 << column))) {
_usedColumns |= (0x01 << column);
_remainingCoulumnCount--;
matrixMatrix[0] |= 0x01 << column;
}
}
}
}
}
if (!_remainingCoulumnCount) {
_counter++;
if (_counter > 11) {
if (!_ereasingDone) {
for (byte i = 0; i < 11; i++) {
matrixTime[i] = matrix[i];
}
_usedColumns = 0;
_remainingCoulumnCount = 12;
_counter = 0;
_ereasingDone = true;
}
else {
_writingDone = true;
}
}
}
return (_writingDone);
}
void Transitions::shiftDownMatrixErease(word matrixMatrix[16], word matrixWeak[16]) {
for (byte i = 10; i > 0; i--) {
matrixMatrix[i] = matrixMatrix[i - 1];
matrixWeak[i] |= matrixWeak[i - 1];
}
matrixWeak[0] = (matrixMatrix[1] | matrixWeak[1]) ;
matrixMatrix[0] = 0;
}
void Transitions::shiftDownMatrixWrite(word matrixMatrix[16], word matrixWeak[16]) {
for (byte i = 10; i > 0; i--) {
matrixMatrix[i] = matrixMatrix[i - 1];
matrixWeak[i] = matrixWeak[i - 1];
}
matrixWeak[0] = (~matrixMatrix[1] & matrixWeak[1]) ;
matrixMatrix[0] = 0;
}