function badgeCode(g, ctx, frameNumber) {
ctx.fillStyle = '#333'
ctx.fillRect(0, 0, width, height);
ctx.lineWidth = 14;
ctx.lineCap = "square";
const cellSize = 50;
const stepSize = cellSize;
const lineHeight = cellSize;
const probability = .20;
const drawLine = (x0, y0, x1, y1) => {
ctx.beginPath();
ctx.moveTo(x0, y0);
ctx.lineTo(x1, y1);
ctx.stroke();
}
const drawRow = (yStart) => {
for (let i = 0; i < width; i += 1) {
const xPoints = [i * stepSize, (i + 1) * stepSize];
const yPoints = [yStart, yStart + lineHeight];
const noiseVal = noise.simplex3(i * stepSize, yStart, frameNumber);
let isFlip = noiseVal < probability;
const points = isFlip ?
[xPoints[0], yPoints[0], xPoints[1], yPoints[1]] :
[xPoints[0], yPoints[1], xPoints[1], yPoints[0]];
const grayValue = 1 - Math.round(noiseVal * 255);
let opacityValue;
if (gradientDirection === 'horizontal') {
opacityValue = 1 - (i * stepSize / width) + .2;
} else if (gradientDirection === 'vertical') {
opacityValue = opacityValue = 1 - (yStart / height) + .15;
} else {
opacityValue = 1;
}
let strokeStyle;
if (!isFlip) {
strokeStyle = chroma(bgColor).alpha(opacityValue - 0.1);
} else {
strokeStyle = chroma(`rgb(${grayValue}, ${grayValue}, ${grayValue})`).alpha(opacityValue);
}
ctx.strokeStyle = strokeStyle;
drawLine(...points);
}
}
for (let i = 0; i < height; i += lineHeight) {
drawRow(i)
}
}