forked from vesteraas/node-pitft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectangles.js
53 lines (39 loc) · 1.24 KB
/
rectangles.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
var pitft = require("../pitft");
var fb = pitft("/dev/fb1"); // Returns a framebuffer in direct mode. See the clock.js example for double buffering mode
// Clear the screen buffer
fb.clear();
var xMax = fb.size().width;
var yMax = fb.size().height;
for (var n=0; n<500; n++) {
var x, y, w, h, r, g, b;
do {
x = parseInt(Math.random() * xMax, 10);
w = parseInt(Math.random() * xMax, 10);
} while ((x + w) >= xMax)
do {
y = parseInt(Math.random() * yMax, 10);
h = parseInt(Math.random() * yMax, 10);
} while ((y + h) >= yMax)
r = Math.random();
g = Math.random();
b = Math.random();
fb.color(r, g, b);
fb.rect(x, y, w, h, false, 1); // Draw an outlined rectangle with a 1 pixel wide border
}
fb.clear();
for (var n=0; n<500; n++) {
var x, y, w, h, r, g, b;
do {
x = parseInt(Math.random() * xMax, 10);
w = parseInt(Math.random() * xMax, 10);
} while ((x + w) >= xMax)
do {
y = parseInt(Math.random() * yMax, 10);
h = parseInt(Math.random() * yMax, 10);
} while ((y + h) >= yMax)
r = Math.random();
g = Math.random();
b = Math.random();
fb.color(r, g, b);
fb.rect(x, y, w, h, true); // Draw a filled rectangle
}