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