-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (75 loc) · 1.94 KB
/
index.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
let x, y;
function getUserCanvas() {
x = document.getElementById(`canvas-x`).value;
y = document.getElementById(`canvas-y`).value;
const arrayBoard = generateBoard(x,y);
drawCanvas(arrayBoard);
console.log("x= ",x);
console.log("y= ",y);
}
const letters = [
{
letter: "F",
shape: [
[0, 0, 0, 0, 0],
[0, 0, 1, 1, 0],
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
],
},
];
// [
// [0, 0, 0],
// [0, 1, 0],
// [1, 1, 1],
// [0, 0, 1],
// [0, 0, 0]
// ]
function rotate(matrix) {
const n = matrix.length;
const x = Math.floor(n/ 2);
const y = n - 1;
for (let i = 0; i < x; i++) {
for (let j = i; j < y - i; j++) {
k = matrix[i][j];
matrix[i][j] = matrix[y - j][i];
matrix[y - j][i] = matrix[y - i][y - j];
matrix[y - i][y - j] = matrix[j][y - i]
matrix[j][y - i] = k
}
}
}
rotate(letters[0].shape);
console.log(letters[0].shape);
rotate(letters[0].shape);
console.log(letters[0].shape);
rotate(letters[0].shape);
console.log(letters[0].shape);
rotate(letters[0].shape);
console.log(letters[0].shape);
function generateBoard(width, height) {
if (!width || !height) {
width = randomNumber();
height = randomNumber();
}
width = width < 5 ? 5 : width;
height = height < 5 ? 5 : height;
return Array.from({ length: width }, (slot) =>
Array.from({ length: height }, (slot) => 0)
);
}
function drawCanvas(arrayOfArrays){
const canvas = document.getElementById(`canvas`);
arrayOfArrays.forEach( rowArray => {
const row = document.createElement('div');
rowArray.forEach( element => {
const col = document.createElement(`div`);
row.appendChild(col);
})
canvas.appendChild(row);
})
}
function randomNumber(max, min) {
return Math.floor(Math.random() * (max - min + 1) + min);
}