xxxxxxxxxx
128
const symbols = {
0: ["1110111","Z"],
1: ["0000011", 0 ],
2: ["0111110", 1 ],
3: ["0011111", 2 ],
4: ["1001011", 3 ],
5: ["1011101", 4 ],
6: ["1111101", 5 ],
7: ["0010011", 6 ],
8: ["1111111", 7 ],
9: ["1011111", 8 ],
A: ["1111011", 9 ],
B: ["1101101","A"],
C: ["1110100","B"],
D: ["0101111","C"],
E: ["1111100","D"],
F: ["1111000","E"],
G: ["1110101","F"],
H: ["0101011","G"],
I: ["0000001","H"],
J: ["0000111","I"],
K: ["XXXXXXX","J"],
L: ["1100100","K"],
M: ["1110011","L"],
N: ["0101001","M"],
O: ["0101101","N"],
P: ["1111010","O"],
Q: ["1011011","P"],
R: ["0101000","Q"],
S: ["XXXXXXX","R"],
T: ["1101000","S"],
U: ["0100101","T"],
V: ["1100111","U"],
W: ["XXXXXXX","V"],
X: ["1101011","W"],
Y: ["1001111","X"],
Z: ["XXXXXXX","Y"]
};
let frame = 0;
let counter = [[0,5], [1,9], ":", [0,5], [0,9]];
function setup() {
createCanvas(500, 500);
}
function draw() {
frame++;
if(frame > 59){
//console.log("Decrementing...", counter);
decrementCounter(counter);
//Play decrement noise
//console.log("Decremented.", counter);
frame = 0;
}
background(0);
fill(255,0,0); stroke(255,0,0);
// drawSymbol(c[4][0], width/2, height/2, 5, true);
drawCounter(counter, width/2, height/2, 5, true);
}
function decrementCounter(c) {
for(let i = c.length - 1; i > -1; i--){
if(!Array.isArray(c[i])) continue;
const s = c[i][0];
if(s != 0){
c[i][0] = symbols[s][1];
break;
}
c[i] = [c[i][1], c[i][1]];
}
}
function drawSymbol(s, x, y, scl = 5, centered = false) {
if(centered) push(), translate(-scl*9/2, -scl*15/2);
let segs = symbols[s][0];
if(segs[0] === "X") return;
if(segs[0] > 0) rect(x, y + scl*2, scl, scl*5);
if(segs[1] > 0) rect(x, y + scl*10, scl, scl*5);
if(segs[2] > 0) rect(x + scl*2, y, scl*5, scl );
if(segs[3] > 0) rect(x + scl*2, y + scl*8, scl*5, scl );
if(segs[4] > 0) rect(x + scl*2, y + scl*16, scl*5, scl );
if(segs[5] > 0) rect(x + scl*8, y + scl*2, scl, scl*5);
if(segs[6] > 0) rect(x + scl*8, y + scl*10, scl, scl*5);
if(centered) pop();
}
function drawColon(x, y, scl = 5, centered = false) {
if(centered) push(), translate(-scl*9/2, -scl*15/2);
circle(x + scl*4.5, y + scl*6, scl);
circle(x + scl*4.5, y + scl*10, scl);
if(centered) pop();
}
function drawCounter(c, x, y, scl = 5, centered = false) {
drawSymbol(c[0][0], x-(20-3)*scl, y, 5, centered);
drawSymbol(c[1][0], x-(10-3)*scl, y, 5, centered);
drawColon ( x, y, 5, centered);
drawSymbol(c[3][0], x+(10-3)*scl, y, 5, centered);
drawSymbol(c[4][0], x+(20-3)*scl, y, 5, centered);
}