-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSongMatrix.js
105 lines (91 loc) · 2.39 KB
/
SongMatrix.js
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
/**
*
*/
let can;
let slider;
let scale = 10;
let songTextInput;
let songLines = [];
let songWords = [];
let words = false;
let showMatrix = false;
function setup() {
can = createCanvas(windowWidth, windowHeight);
background(200);
processSongText()
noLoop();
}
function draw() {
words = document.getElementById("wordsRadio").checked;
scale = document.getElementById("slider").value;
if (showMatrix) {
if (words) {
can = createCanvas((songWords.length) * scale, (songWords.length) * scale)
background(200);
for (let i = 0; i < songWords.length; i++) {
for (let j = 0; j < songWords.length; j++) {
if (songWords[i] === songWords[j]) {
if (i == j) {
fill(0, 255, 0);
} else {
fill(200, 0, 100);
}
rect(i * scale, j * scale, scale - 1, scale - 1);
}
}
}
} else {
background(200);
can = createCanvas((songLines.length) * scale, (songLines.length) * scale)
for (let i = 0; i < songLines.length; i++) {
for (let j = 0; j < songLines.length; j++) {
if (songLines[i] === songLines[j]) {
if (i == j) {
fill(0, 255, 0);
} else {
fill(200, 0, 100);
}
rect(i * scale, j * scale, scale - 1, scale - 1);
}
}
}
console.log("ELSE");
}
}
}
function myFunction() {
showMatrix = true;
processSongText()
draw();
//loop();
}
function saveToIMG(){
saveCanvas(can, 'SongMatrix', 'jpg');
}
function isEmpty(str) {
return (!str || 0 === str.length || !str.trim());
}
function processSongText() {
songTextInput = document.getElementById("songText_TextArea").value;
if (isEmpty(songTextInput)) {
console.log("Songtext is missing")
return null;
} else {
console.log("Songtext is there")
songTextInput = songTextInput.trim();
songTextInput = songTextInput.replace(/,/g, ' ');
songTextInput = songTextInput.replace(/\(/g, ' ');
songTextInput = songTextInput.replace(/\)/g, ' ');
songLines = songTextInput.split(/\r?\n/g)
var songWordsSplit = songTextInput.split(/\r\n|\r|\n|\s/g)
let j = 0;
for (var i = 0; i < songWordsSplit.length; i++) {
if (!isEmpty(songWordsSplit[i])) {
songWords[j] = songWordsSplit[i].trim();
j++;
}
}
// document.getElementById("output").innerHTML = songLines;
document.getElementById("output").innerHTML = songWords;
}
}