-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
94 lines (85 loc) · 2.23 KB
/
main.ts
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
class LedDisplay {
private static allLeds: Array<{ x: number, y: number }> = [
{ x: 0, y: 0 },
{ x: 0, y: 1 },
{ x: 0, y: 2 },
{ x: 0, y: 3 },
{ x: 0, y: 4 },
{ x: 1, y: 0 },
{ x: 1, y: 1 },
{ x: 1, y: 2 },
{ x: 1, y: 3 },
{ x: 1, y: 4 },
{ x: 2, y: 0 },
{ x: 2, y: 1 },
{ x: 2, y: 2 },
{ x: 2, y: 3 },
{ x: 2, y: 4 },
{ x: 3, y: 0 },
{ x: 3, y: 1 },
{ x: 3, y: 2 },
{ x: 3, y: 3 },
{ x: 3, y: 4 },
{ x: 4, y: 0 },
{ x: 4, y: 1 },
{ x: 4, y: 2 },
{ x: 4, y: 3 },
{ x: 4, y: 4 },
];
image: Array<{ x: number, y: number }>;
constructor(image: Array<{ x: number, y: number }>) {
this.image = image;
}
activate(): void {
for (let i = 0; i < LedDisplay.allLeds.length; i++) {
let currentLed: { x: number, y: number } = LedDisplay.allLeds[i];
if (this.image.some((element) => this.shallowEqual(currentLed, element))) {
led.plot(LedDisplay.allLeds[i].x, LedDisplay.allLeds[i].y);
} else {
led.unplot(LedDisplay.allLeds[i].x, LedDisplay.allLeds[i].y);
}
}
}
private shallowEqual(object1: { x: number, y: number }, object2: { x: number, y: number }): boolean {
if (object1["x"] !== object2["x"]) {
return false;
}
if (object1["y"] !== object2["y"]) {
return false;
}
return true;
}
}
const line: LedDisplay = new LedDisplay([
{ x: 0, y: 1 },
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 1 },
{ x: 4, y: 1 },
])
const square: LedDisplay = new LedDisplay([
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: 2, y: 0 },
{ x: 3, y: 0 },
{ x: 4, y: 0 },
{ x: 0, y: 1 },
{ x: 4, y: 1 },
{ x: 0, y: 2 },
{ x: 4, y: 2 },
{ x: 0, y: 3 },
{ x: 4, y: 3 },
{ x: 0, y: 4 },
{ x: 1, y: 4 },
{ x: 2, y: 4 },
{ x: 3, y: 4 },
{ x: 4, y: 4 },
]);
input.onButtonPressed(Button.A, function () {
square.activate();
})
input.onButtonPressed(Button.B, function () {
line.activate();
})
basic.forever(function () {
})