cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

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.

            
              - var L = 8; // size of the curve
- var N = L; // order of the curve
- var M = L * L - 1; // number of circles

// From https://en.wikipedia.org/wiki/Hilbert_curve
- function hilbert(n, d) {
-   var rx, ry, t = d;
-   var x = 0, y = 0;
-   for (var s = 1; s < n; s *= 2) {
-     rx = 1 & (t / 2);
-     ry = 1 & (t ^ rx);
-     if (ry == 0) {
-       if (rx == 1) {
-         x = s - 1 - x;
-         y = s - 1 - y;
-       }
-       var tmp = x;
-       x = y;
-       y = tmp;
-     }
-     x += s * rx;
-     y += s * ry;
-     t /= 4;
-   }
-   return {x: x, y: y};
- }

div(
  id="circles",
  style="width: #{L}em; height: #{L}em;"
)
  - for (var d = 0; d < M; d++) {
  -   var p = hilbert(N, d);
  -   var np = hilbert(N, d + 1);
  -   var dir;
  -   if (np.x > p.x) dir = "left";
  -   else if (np.x < p.x) dir = "right";
  -   else if (np.y > p.y) dir = "down";
  -   else if (np.y < p.y) dir = "up";
      span(
        class="circle move-#{dir}",
        style="\
          margin-left: #{p.x}em;\
          margin-top: #{p.y}em;\
        "
      )
  - }
            
          
!
            
              $timing-function: ease-in-out
$duration: 2s
$margin: 0.5em

html, body
  height: 100%

body
  font-size: 6vmin
  display: flex
  align-items: center
  justify-content: center
  flex-direction: column
  background-color: #022B3A

#circles
  display: inline-block
  position: relative

@mixin move($dir, $ox, $oy) 
  &.move-#{$dir}
    animation: move-#{$dir} $duration $timing-function infinite
    &:first-child
      animation-name: move-#{$dir}-first
    &:last-child
      animation-name: move-#{$dir}-last
  
  @keyframes move-#{$dir}
    0%
      transform: translate(0em, 0em)
      box-shadow: 0px 0px 0.2em -0.2em
    50%
      box-shadow: (-$ox)/6 (-$oy)/6 0.2em -0.1em
    100%
      transform: translate($ox, $oy)
      box-shadow: 0px 0px 0.2em -0.2em

  @keyframes move-#{$dir}-first
    0%
      transform: translate(0em, 0em) scale(0)
      box-shadow: 0px 0px 0.2em -0.2em
      opacity: 0
    50%
      box-shadow: (-$ox)/6 (-$oy)/6 0.2em -0.1em
    100%
      transform: translate($ox, $oy) scale(1)
      box-shadow: 0px 0px 0.2em -0.2em
      opacity: 1

  @keyframes move-#{$dir}-last
    0%
      transform: translate(0em, 0em) scale(1)
      box-shadow: 0px 0px 0.2em -0.2em
      opacity: 1
    50%
      box-shadow: (-$ox)/6 (-$oy)/6 0.2em -0.1em
    100%
      transform: translate($ox, $oy) scale(0)
      box-shadow: 0px 0px 0.2em -0.2em
      opacity: 0

.circle
  display: inline-block
  color: #E1E5F2
  background-color: #E1E5F2
  box-shadow: 0px 0px 0.2em -0.2em
  width: 1em - $margin
  height: 1em - $margin
  border-radius: 1em
  position: absolute
  line-height: 0px
  border: 0px solid #000

  @include move("left", 1em, 0em)
  @include move("right", -1em, 0em)
  @include move("down", 0em, 1em)
  @include move("up", 0em, -1em)

            
          
!
999px
Loading ..................

Console