Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                p Click anywhere on the grid to start, but the top right corner is the best spot. And you need to have 'Experimental Web Platform Features' flag enabled to make it working 🤷‍♂️

- var n = 20;

mixin child(pos, limit)
  if limit
    span(class='a' + (Math.floor((limit - 1) / n) % 2 === 1 ? 'a' : '') + (pos+1), tabindex=1)
      +child((pos + 1) % n, limit - 1)

.container
  +child(0, n * n)
              
            
!

CSS

              
                $size: 30px;
$n: 20;

.container {
  width: $size * $n;
}

:root {
  @for $i from 1 through $n {
    --a-#{$i}: 0;
    --aa-#{$i}: 0;
  }
}

// 110, 101, 011, 010, 001 => 1
// 111, 100, 000 => 0
// xyz || x!y!z || !x!y!z == xyz || !y!z

@for $i from 1 through $n {
  span.aa#{$i} {
    // Long and not efficient
    // --aa-#{$i}: calc(
    //   var(--a-#{$i - 1}, 0) * var(--a-#{$i}, 0) * (1 - var(--a-#{$i + 1}, 0)) +
    //   var(--a-#{$i - 1}, 0) * (1 - var(--a-#{$i}, 0)) * var(--a-#{$i + 1}, 0) +
    //   (1 - var(--a-#{$i - 1}, 0)) * var(--a-#{$i}, 0) * var(--a-#{$i + 1}, 0) +
    //   (1 - var(--a-#{$i - 1}, 0)) * var(--a-#{$i}, 0) * (1 - var(--a-#{$i + 1}, 0)) +
    //   (1 - var(--a-#{$i - 1}, 0)) * (1 - var(--a-#{$i}, 0)) * var(--a-#{$i + 1}, 0),
    //   0
    // );
    
    // Short and efficient
    --aa-#{$i}: calc(1 - (
      var(--a-#{$i - 1}, 0) * var(--a-#{$i}, 0) * var(--a-#{$i + 1}, 0) +
      (1 - var(--a-#{$i}, 0)) * (1 - var(--a-#{$i + 1}, 0))
      0)
    );
  }
  span.a#{$i} {
    // Long and not efficient
    // --a-#{$i}: calc(
    //   var(--aa-#{$i - 1}, 0) * var(--aa-#{$i}, 0) * (1 - var(--aa-#{$i + 1}, 0)) +
    //   var(--aa-#{$i - 1}, 0) * (1 - var(--aa-#{$i}, 0)) * var(--aa-#{$i + 1}, 0) +
    //   (1 - var(--aa-#{$i - 1}, 0)) * var(--aa-#{$i}, 0) * var(--aa-#{$i + 1}, 0) +
    //   (1 - var(--aa-#{$i - 1}, 0)) * var(--aa-#{$i}, 0) * (1 - var(--aa-#{$i + 1}, 0)) +
    //   (1 - var(--aa-#{$i - 1}, 0)) * (1 - var(--aa-#{$i}, 0)) * var(--aa-#{$i + 1}, 0),
    //   0
    // );
    
    // Short and efficient
    --a-#{$i}: calc(1 - (
      var(--aa-#{$i - 1}, 0) * var(--aa-#{$i}, 0) * var(--aa-#{$i + 1}, 0) +
      (1 - var(--aa-#{$i}, 0)) * (1 - var(--aa-#{$i + 1}, 0))
      0)
    );
  }
}

span::before {
  height: $size;
  width: $size;
  display: inline-block;
  box-sizing: border-box;
  text-align: center;
  line-height: $size;
  content: '・';
  background: black;
  color: white;
  border: 1px solid gray;
}

// The way to indicate the result
@for $i from 1 through $n {
  span.a#{$i}::before {
    --l: calc(1 - var(--a-#{$i}, 0));
    background: hsl(0, 0%, calc(100% * var(--l)));
  }
  span.aa#{$i}::before {
    --l: calc(1 - var(--aa-#{$i}, 0));
    background: hsl(0, 0%, calc(100% * var(--l)));
  }
  
  span.a#{$i}:focus {
    --a-#{$i}: 1;
  }
  span.aa#{$i}:focus {
    --aa-#{$i}: 1;
  }
}

              
            
!

JS

              
                // Don't blame me, we'll have CSS syntax for that in future:
// https://github.com/w3c/css-houdini-drafts/issues/137#issuecomment-433037224
for (var i=1; i++; i<=20) {
  CSS.registerProperty({
    name: '--a-' + i,
    syntax: '<number>',
    inherits: true,
    initialValue: 0
  });
  CSS.registerProperty({
    name: '--aa-' + i,
    syntax: '<number>',
    inherits: true,
    initialValue: 0
  });
}
              
            
!
999px

Console