{%- set w, h = 10, 10 -%}
<!DOCTYPE html>
<html>
<head>
<style>
body, div {
line-height: 0;
}
:root {
{%- for wi in range(w) -%}
--v{{wi}}: 0;
{%- endfor -%}
}
div.v {
{%- for wi in range(w) -%}
{%- macro b(shift) -%}
var(--b{{(shift + wi) % w}})
{%- endmacro -%}
{%- set p, q, r = b(-1), b(0), b(1) -%}
--v{{wi}}: calc(
1 - (
1 - ({{q}} * (1 - {{p}}))
) * (
1 - ({{q}} + {{r}} - 2 * {{q}} * {{r}})
)
);
{%- endfor -%}
}
div.b {
{%- for wi in range(w) -%}
--b{{wi}}: var(--v{{wi}});
{%- endfor -%}
}
[class^="c"] {
display: inline-block;
width: 20px;
height: 20px;
border: 1px solid gray;
}
{%- for wi in range(w) -%}
.c{{wi}} {
background-color: hsl(0, 0%, calc(100% - 100% * var(--v{{wi}})));
}
input#i{{wi}}:checked~div {
--v{{wi}}: 1;
}
{%- endfor -%}
label {
border: 1px solid gray;
display: inline-block;
height: 20px;
width: 20px;
background-color: white;
}
input {
display: none;
}
input:checked + label {
background-color: black;
}
</style>
</head>
<body>
{%- for wi in range(w) -%}
<input id="i{{wi}}" type="checkbox"><label for="i{{wi}}"></label>
{%- endfor -%}
<div class="b">
{%- for i in range(h - 1) -%}
<div class="v"><div class="b">
{%- for wi in range(w) -%}
<span class="c{{wi}}"></span>
{%- endfor -%}
{%- endfor -%}
{%- for i in range(h - 1) -%}
</div></div>
{%- endfor -%}
</div>
</body>
</html>