-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex_144.js
154 lines (139 loc) · 3.48 KB
/
ex_144.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
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
154
/**
* Example for 1.44" 128x128 resolution
*/
const {ST7735} = require('./index');
const font = require('@niklauslee/font-lee-sans');
const image = require('@kaluma/logo-mono');
const st7735 = new ST7735();
st7735.setup(board.spi(0), {
width: 128,
height: 128,
xstart: 2,
ystart: 3,
dc: 20,
rst: 21,
cs: 17,
rotation: 0
});
const gc = st7735.getContext('buffer');
const t = 3000;
const colors = [
gc.color16(255, 255, 255), // white
gc.color16(255, 0, 0), // red
gc.color16(0, 255, 0), // green
gc.color16(0, 0, 255), // blue
gc.color16(255, 255, 0),
gc.color16(255, 0, 255),
gc.color16(0, 255, 255),
gc.color16(127, 127, 127),
];
// start
gc.clearScreen();
gc.setFontColor(gc.color16(255, 255, 255));
gc.setColor(colors[0]);
gc.drawRect(0, 0, st7735.width - 1, st7735.height - 1);
gc.drawText(10, 10, "Graphics Examples");
gc.display();
delay(t);
// pixels
gc.clearScreen();
for (let x = 0; x < gc.getWidth(); x += 5) {
for (let y = 0; y < gc.getHeight(); y += 5) {
gc.setPixel(x, y, 0xffff);
}
}
gc.display();
delay(t);
// lines
gc.clearScreen();
let c = 0;
for (let x = 0; x < gc.getWidth(); x += 5) {
gc.setColor(colors[c]);
gc.drawLine(0, 0, x, gc.getHeight() - 1);
gc.drawLine(gc.getWidth() - 1, 0, x, gc.getHeight() - 1);
c++; if (c > colors.length-1) c = 0;
}
gc.display();
delay(t);
// rectangles
gc.clearScreen();
c = 0;
for (let x = 0; x < gc.getWidth(); x += 5) {
gc.setColor(colors[c]);
if ((x * 2) < Math.min(gc.getHeight(), gc.getWidth())) {
gc.drawRect(x, x, gc.getWidth() - (x * 2), gc.getHeight() - (x * 2));
}
c++; if (c > colors.length-1) c = 0;
}
gc.display();
delay(t);
// filled rectangles
gc.clearScreen();
c = 0;
for (let x = 0; x < gc.getWidth(); x += 10) {
for (let y = 0; y < gc.getWidth(); y += 10) {
if ((((x + y) / 10) % 2) === 0) {
gc.setFillColor(colors[c]);
gc.fillRect(x, y, 10, 10);
c++; if (c > colors.length-1) c = 0;
}
}
}
gc.display();
delay(t);
// circles
gc.clearScreen();
c = 0;
for (let x = 0; x < gc.getWidth(); x += 30) {
for (let y = 0; y < gc.getWidth(); y += 30) {
gc.setColor(colors[c]);
gc.setFillColor(colors[c]);
gc.drawCircle(x + 15, y + 15, 14);
gc.fillCircle(x + 15, y + 15, 8);
c++; if (c > colors.length-1) c = 0;
}
}
gc.display();
delay(t);
// round rectangles
gc.clearScreen();
c = 0;
for (let x = 0; x < gc.getWidth(); x += 30) {
for (let y = 0; y < gc.getWidth(); y += 20) {
gc.setColor(colors[c]);
gc.setFillColor(colors[c]);
gc.drawRoundRect(x, y, 28, 18, 5);
gc.fillRoundRect(x + 3, y + 3, 22, 12, 4);
c++; if (c > colors.length-1) c = 0;
}
}
gc.display();
delay(t);
// font
gc.clearScreen();
gc.setFontColor(0xffff);
gc.drawText(0, 0, "ABCDEFGHIJKLMN\nOPQRSTUVWXYZ\nabcdefghijklmn\nopqrstuvwxyz\n0123456789\n~!@#$%^&*()-=_+\n[]{}\\|:;'<>/?.,");
gc.display();
delay(t);
// font scale
gc.clearScreen();
gc.setFontColor(0xffff);
gc.setFontScale(3, 3);
gc.drawText(0, 0, "ABCDEFGHIJKLMN\nOPQRSTUVWXYZ\nabcdefghijklmn\nopqrstuvwxyz\n0123456789\n~!@#$%^&*()-=_+\n[]{}\\|:;'<>/?.,");
gc.setFontScale(1, 1);
gc.display();
delay(t);
// custom font
gc.clearScreen();
gc.setFontColor(0xffff);
gc.setFont(font);
gc.setFontScale(1, 1);
gc.drawText(0, 0, 'Custom Font\n"Lee Sans"\nVariable-width Font');
gc.display();
delay(t);
// bitmap (rgb)
gc.clearScreen();
let x = Math.floor((gc.getWidth() - image.width) / 2);
let y = Math.floor((gc.getHeight() - image.height) / 2);
gc.drawBitmap(x, y, image, {color: gc.color16(0, 255, 0)});
gc.display();