-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSerialMatrix.sc
99 lines (75 loc) · 1.83 KB
/
SerialMatrix.sc
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
/*
Description: Creates a matrix with all possible serial combinations
USAGE:
a = SerialMatrix.new([1, 2, 3, 4, 5])
a.gui
a.org(0)
a.inv(5)
a.rev(10)
a.invRev
a.revInv
a.matrix
a.size
a.asMatrix
a.at(3, 2)
*/
SerialMatrix {
var <>list, <size, <inversion, <transpositions, <matrix;
*new { arg list;
^super.new.init(list);
}
init { arg thisSeq;
list = thisSeq;
size = list.size;
inversion = Array.fill(size,
{|i|
(list[0]-(list[i]-list[0]))%size
});
transpositions = inversion-list[0]%size;
matrix = Array.fill(size, {|i| (list + transpositions[i])%size});
}
asMatrix {
^Matrix.with(matrix)
}
at { arg thisRow, thisCol;
^this.asMatrix.at(thisRow, thisCol)
}
gui {
var w, numberBoxes;
w=Window("SerialMatrix",Rect(261, 206, 100 + (size*23) , 100 + (size*23))).front;
numberBoxes = Array.fill(size,{|j|
Array.fill(size, {|i|
NumberBox(w,Rect(10+(i*25),10+(j*25),20,20))
});
});
size.do({|i|
size.do({|j|
numberBoxes[i][j].value = matrix[i][j];
})
});
w.front;
}
post {
matrix.postnl;
}
org {arg number=0;
number = number.round.abs%size;
^matrix[number];
}
rev {arg number=0;
number = number.round.abs%size;
^matrix[number].reverse;
}
inv {arg number=0;
number = number.round.abs%size;
^matrix.flop[number];
}
invRev {arg number=0;
number = number.round.abs%size;
^matrix.flop[number].reverse;
}
revInv {arg number=0;
number = number.round.abs%size;
^matrix.flop[number].reverse;
}
}