Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Behavior

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              mixin block
  .block(class!=attributes.class)
    .right
    .left
    .top
    .bottom
    .front
    .back

.title
  span Day 17. Zombie

.scene
  +block(class="grass-left")
  +block(class="grass-right")
  +block(class="road")
  +block(class="head")
  +block(class="neck")
  +block(class="body")
  +block(class="left-hand")
  +block(class="right-hand")
  +block(class="left-boot")
  +block(class="right-boot")
  +block(class="left-leg")
  +block(class="right-leg")

<div class="controls">
  <span>x: </span><input type="range" value="0" min="-360" max="360" id="x-angle-r" oninput="setX(this.value)">
  <input type="number" value="0" min="-360" max="360" id="x-angle-n" oninput="setX(this.value)">
  <br>
  <span>z: </span><input type="range" value="0" min="-360" max="360" id="z-angle-r" oninput="setZ(this.value)">
  <input type="number" value="0" min="-360" max="360" id="z-angle-n" oninput="setZ(this.value)">
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Pacifico');

:root {
	--x-angle: 0deg;
	--z-angle: 0deg;
}

$c: 1; // scale coefficient
$time: 3s; // animation time
$easing: ease; // animation timing function

$zombieColor: #B1C4B3;
$grassColor: #264;
$zombieBlocks: 
  ('head', 60, 60, 60, 120, 120, 120, $zombieColor),
  ('neck', 20, 20, 20, 140, 140, 100, $zombieColor),
  ('body', 50, 60, 40, 125, 135, 50, $zombieColor),
  ('left-hand', 20, 20, 90, 110, 140, 91, $zombieColor),
  ('right-hand', 20, 20, 90, 170, 140, 91, $zombieColor),
  ('left-leg', 25, 60, 40, 125, 135, 10, $zombieColor),
  ('right-leg', 25, 60, 40, 150, 135, 10, $zombieColor),
  ('left-boot', 25, 15, 50, 125, 135, 0, $zombieColor),
  ('right-boot', 25, 15, 50, 150, 135, 0, $zombieColor);

$staticBlocks: 
  ('grass-left', 100, 23, 300, 0, 0, -20, $grassColor),
  ('grass-right', 100, 23, 300, 200, 0, -20, $grassColor),
  ('road', 100, 20, 300, 100, 0, -20, #666);

body {
  display: flex;
  width: 100vw;
  height: 100vh;
  background-color: #246;
  overflow: hidden;
  perspective: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.title {  
  padding: 10px 20px;
  font-family: 'Pacifico', cursive;
  position: absolute;
  
  span {
    font-size: 20px;
    font-weight: bold;
    color: rgba(0,0,0,0.5);
  }
}

.scene {
  $w: 300px * $c;
  $h: 300px * $c;
  display: block;
  margin: auto;
  width: $w;
  height: $h;
	transform-style: preserve-3d;
  transform: rotatex(var(--x-angle)) rotatez(var(--z-angle));
  will-change: transform;
}

@mixin fringe($w, $h, $color) {
	transform-style: preserve-3d;
  display: block;
  width: $w;
  height: $h;
  background-color: $color;
  border: 1px solid rgba(0,0,0,0.02);
  position: absolute;
  box-sizing: border-box;
  will-change: transform;
}

@mixin front($w, $h, $d, $color) {
  @include fringe($w, $h, $color);
  transform-origin: top center;
  transform: translate3d(0, $d, $h) rotatex(-90deg);
}

@mixin back($w, $h, $d, $color) {
  @include fringe($w, $h, $color);
  transform-origin: top center;
  transform: translate3d(0, 0, 0) rotatex(90deg);
}

@mixin right($w, $h, $d, $color) {
  @include fringe($d, $h, $color);
  transform-origin: top left;
  transform: translate3d($w, 0, 0) rotatex(90deg) rotatey(90deg);
}

@mixin left($w, $h, $d, $color) {
  @include fringe($d, $h, $color);
  transform-origin: top left;
  transform: translate3d(0, 0, 0) rotatex(90deg) rotatey(90deg);
}

@mixin top($w, $h, $d, $color) {
  @include fringe($w, $d, $color);
  transform: translate3d(0, 0, $h);
}

@mixin bottom($w, $h, $d, $color) {
  @include fringe($w, $d, $color);
  transform: translate3d(0, 0, 0);
}

.block {
  display: block;  
	transform-style: preserve-3d;
  position: absolute;
  top: 0;
  left: 0;
}

@mixin block($w, $h, $d, $x, $y, $z, $color, $angle: '0, 0, 0, 0') {
  transform: translate3d($x, $y, $z) rotate3d(#{$angle});
  will-change: transform;
  .front { @include front($w, $h, $d, $color); }
  .back { @include back($w, $h, $d, $color); }
  .right { @include right($w, $h, $d, darken($color, 10%)); }
  .left { @include left($w, $h, $d, darken($color, 10%)); }
  .top { @include top($w, $h, $d, darken($color, 5%)); }
  .bottom { @include bottom($w, $h, $d, darken($color, 5%)); }
}

@for $m from 1 through length($staticBlocks) {
	.#{nth(nth($staticBlocks, $m), 1)} {
    $w: nth(nth($staticBlocks, $m), 2) * $c;
    $h: nth(nth($staticBlocks, $m), 3) * $c;
    $d: nth(nth($staticBlocks, $m), 4) * $c;
    $x: nth(nth($staticBlocks, $m), 5) * $c;
    $y: nth(nth($staticBlocks, $m), 6) * $c;
    $z: nth(nth($staticBlocks, $m), 7) * $c;
    $color: nth(nth($staticBlocks, $m), 8);
    @include block(#{$w}px, #{$h}px, #{$d}px, #{$x}px, #{$y}px, #{$z}px, $color);
  }
}

@for $n from 1 through length($zombieBlocks) {
	.#{nth(nth($zombieBlocks, $n), 1)} {
    $w: nth(nth($zombieBlocks, $n), 2) * $c;
    $h: nth(nth($zombieBlocks, $n), 3) * $c;
    $d: nth(nth($zombieBlocks, $n), 4) * $c;
    $x: nth(nth($zombieBlocks, $n), 5) * $c;
    $y: nth(nth($zombieBlocks, $n), 6) * $c;
    $z: nth(nth($zombieBlocks, $n), 7) * $c;
    $color: nth(nth($zombieBlocks, $n), 8);
    @include block(#{$w}px, #{$h}px, #{$d}px, #{$x}px, #{$y}px, #{$z}px, $color);
    animation: #{nth(nth($zombieBlocks, $n), 1)}-animation $time/2 $easing infinite;
    animation-delay: -($time / 4);

    @keyframes #{nth(nth($zombieBlocks, $n), 1)}-animation {
      0%, 100% {
        transform: translate3d(#{$x}px, #{$y}px, #{$z + 2 * $c}px);
      }
      50% {
        transform: translate3d(#{$x}px, #{$y}px, #{$z}px);
      }
    }
  }
}

.head {
  .front {
    background-color: $zombieColor;
    background-image: linear-gradient(#422, #422);
    background-repeat: no-repeat;
    background-size: 50% 5%;
    background-position: 50% 80%;
    &::before, &::after {
      content: '';
      position: absolute;
      background-color: #eee;
      background-image: 
        linear-gradient(#eee, #eee),
        linear-gradient(#eee, #eee),
        linear-gradient(#000, #000);
      background-position:
        60% 60%,
        30% 30%,
        0 0;
      background-size:
        15% 15%,
        30% 30%,
        100% 100%;
      background-repeat: no-repeat;
      display: block;
      width: 30%;
      height: 30%;
      top: 30%;
      border-radius: 5px * $c;
    }
    &::before {      
      left: 10%;
    }
    &::after {
      left: 60%;
    }
  }
}

@mixin leg-animation($x, $y, $z) {
    0%, 100% {
      transform: translate3d($x, $y + 6px * $c, $z) rotate3d(1, 0, 0, 5deg);
    }
    50% {
      transform: translate3d($x, $y - 11px * $c, $z) rotate3d(1, 0, 0, -10deg);
    }
}

.left-leg {
  animation: left-leg-animation $time $easing infinite;
  
  @keyframes left-leg-animation {
    @include leg-animation(125px*$c, 135px*$c, 10px*$c);
  }
}

.right-leg {
  animation: right-leg-animation $time $easing infinite;
  animation-delay: -($time / 2);
  
  @keyframes right-leg-animation {
    @include leg-animation(150px*$c, 135px*$c, 10px*$c);
  }
}

@mixin boot-animation($x, $y, $z) {
    0%, 100% {
      transform: translate3d($x, $y + 6px * $c, $z);
    }
    50% {
      transform: translate3d($x, $y - 11px * $c, $z);
    }
}

.left-boot {
  animation: left-boot-animation $time $easing infinite;
  
  @keyframes left-boot-animation {
    @include boot-animation(125px * $c, 135px * $c, 0);
  }
}

.right-boot {
  animation: right-boot-animation $time $easing infinite;
  animation-delay: -($time / 2);
  
  @keyframes right-boot-animation {
    @include boot-animation(150px * $c, 135px * $c, 0);
  }
}

.grass-left, 
.grass-right {
  .top {
    $grassDotColor: darken($grassColor, 8%);
    overflow: hidden;
    &::before, &::after {
      position: absolute;
      display: block;
      content: '';
      background: $grassDotColor;
      width: 20px * $c;
      height: 20px * $c;
      top: 100%;
      left: 10%;
      box-shadow:
        60px*$c 75px*$c 0 0 $grassDotColor,
        30px*$c 150px*$c 0 0 $grassDotColor,
        40px*$c 225px*$c 0 0 $grassDotColor;
      animation: grass-animation $time*20 $easing infinite;
      animation-delay: -$time*20;
    }
    &::after {
      animation-delay: -$time*10;
    }
  }
}

.grass-right {
  .top {
    &::before {
      animation-delay: -$time*12.5;
    }
    &::after {
      animation-delay: -$time*2.5;
    }
  }
}

@keyframes grass-animation {
  @for $s from 0 through 40 {
    #{2.5% * $s} { top: (100% - $s * 5%); }
  }
}





.controls {
  position: absolute;
  left: 0;
  bottom: 0;
	margin-left: 10px;
	margin-bottom: 10px;
  background: hsla(190, 70, 70, 0.5);
  border: hsla(190, 50, 50, 0.5) solid 1px;
  padding: 5px 10px;
  border-radius: 5px;
  line-height: 14px;
  font-size: 12px;
  opacity: 0.2;
  transition: opacity 0.3s $easing;
  > * {
    vertical-align: middle;
  }
  
  &:hover {
    opacity: 1;
  }
}

            
          
!
            
              function setX(x) {
	document.documentElement.style.setProperty('--x-angle', x + 'deg');
  document.getElementById("x-angle-r").value = x;
  document.getElementById("x-angle-n").value = x;
}

function setZ(z) {
	document.documentElement.style.setProperty('--z-angle', z + 'deg');
  document.getElementById("z-angle-r").value = z;
  document.getElementById("z-angle-n").value = z;
}

setX(65);
setZ(-24);
            
          
!
999px

Console