-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathring_display.js
100 lines (84 loc) · 1.9 KB
/
ring_display.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
sketch.default2d();
inlets = 1;
var backgroundColor = [ 25 / 255, 31 / 255, 36 / 255, 0.0];
var ringColor = [248 / 255, 202 / 255, 58 / 255, 0.9];
var ringColor2 = [226 / 255, 226 / 255, 226 / 255, 8.0];
var ringRadius = 0.75;
var bitRadius = 0.10;
var bits = Array(16);
for (i=0; i<bits.length; i++) {
bits[i] = 0;
}
var vtask = new Task(taskfun);
vtask.interval = 10;
vtask.repeat();
draw();
function draw() {
with (sketch) {
// erase background
glclearcolor(backgroundColor);
glclear();
glenable("line_smooth");
}
//drawRing();
drawBits();
}
function drawRing() {
with (sketch) {
gllinewidth(2);
// draw ring
moveto(0,0);
glcolor(ringColor2);
framecircle(ringRadius);
}
}
function drawBits() {
if(checkBitValidity(bits)) {
var deltaAngle = 2 * Math.PI / bits.length;
with (sketch) {
gllinewidth(1);
for (i=0; i<bits.length; i++) {
moveto(ringRadius * Math.cos(i*deltaAngle), ringRadius * Math.sin(i*deltaAngle));
glcolor(backgroundColor);
circle(bitRadius);
glcolor(ringColor2);
framecircle(bitRadius);
if (bits[i] == 1) {
glcolor(ringColor);
circle(0.5 * bitRadius);
}
}
}
}
}
function list() {
if(checkBitValidity(arguments)) {
bits = arguments;
}
}
function checkBitValidity(bits) {
for (i=0; i<bits.length; i++) {
if ((bits[i] != 0) && (bits[i] != 1)) {
return false;
};
}
return true;
}
function taskfun() {
draw();
refresh();
}
taskfun.local = 1; //private
function forcesize(w,h) {
if (w!=h) {
h = w;
box.size(w,h);
}
}
forcesize.local = 1; //private
function onresize(w,h) {
forcesize(w,h);
draw();
refresh();
}
onresize.local = 1;