xxxxxxxxxx
50
let nums = [0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B];
let index = 0;
function setup() {
createCanvas(400, 400);
frameRate(3);
}
function draw() {
background(0);
sevenSegment(nums[index]);
index = (index + 1) % nums.length;
}
function getColour(val, shift) {
let r = map((val >> shift) & 1, 0, 1, 50, 255);
let g = 0;
let b = 0;
let a = 255;
return color(r, g, b, a);
}
function sevenSegment(val) {
push();
stroke(0);
noFill();
// A
fill(getColour(val, 6));
rect(60, 20, 78, 18, 10);
// B
fill(getColour(val, 5));
rect(140, 40, 18, 98, 10);
// C
fill(getColour(val, 4));
rect(140, 160, 18, 98, 10);
// D
fill(getColour(val, 3));
rect(60, 260, 78, 18, 10);
// E
fill(getColour(val, 2));
rect(40, 160, 18, 98, 10);
// F
fill(getColour(val, 1));
rect(40, 40, 18, 98, 10);
// G
fill(getColour(val, 0));
rect(60, 140, 78, 18, 10);
pop();
}