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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              .polyhedron.polyhedron--rhombic-dodecahedron
  -(1..12).each do |i|
    .piece.polyhedron--rhombic-pyramid
      -(1..4).each do |i|
        .face.face--lateral-triangle
      .face.face--base-rhombus
            
          
!
            
              // EDITABLE STUFF
$a: 8em; // small diagonal of rhombus
$te: 5s; // explosion animation duration
$tr: $te; // rotation animation duration
$shades: dodgerblue royalblue cornflowerblue deepskyblue 
    lightskyblue lightseagreen darkturquoise cadetblue 
    lightblue teal skyblue aqua;
$of: .3; // opacity factor
$bc: black; // border of rhombic/ triangular faces 

// DO NOT CHANGE STUFF
$n: 12;

// TRIGONOMETRY STUFF
$pi: pi()*1rad;

$angle-units:
  'rad'        'deg'        'grad'          'turn'       '', 
      1   180deg/$pi   200grad/$pi   1turn/(2*$pi)   1/1rad;

@function convert-unit($table, $value-in, $unit-out) {
  $units: nth($table, 1);
  $factors: nth($table, 2);
  
  $idx-in: index($units, unit($value-in));
  $idx-out: index($units, $unit-out);
  
  $result: false;
  
  @if $idx-in and $idx-out {
    $result: 
      $value-in*nth($factors, $idx-out)/nth($factors, $idx-in);
  }
  @else {
    @warn 'Cannot convert #{unit($value-in)} to $#{$unit-out}.';
  }
  
  @return $result;
}

@function convert-angle($value-in, $unit-out) {
  @return convert-unit($angle-units, $value-in, $unit-out);
}

@function rad($value-in) {
  @return convert-angle($value-in, 'rad');
}

@function deg($value-in) {
  @return convert-angle($value-in, 'deg');
}

@function grad($value-in) {
  @return convert-angle($value-in, 'grad');
}

@function turn($value-in) {
  @return convert-angle($value-in, 'turn');
}

@function strip-rad($value-in) {
  @return convert-angle($value-in, '');
}


@function sinu($angle) {
  @return sin(strip-rad($angle));  
}

@function cosu($angle) {
  @return cos(strip-rad($angle));
}

@function tanu($angle) {
  @return tan(strip-rad($angle));
}


@function asin($value, $unit: 'rad', $precision: 25) {
  $coeff: 1;
  $sum: 0;
  $flag: 0;
  $sign: 1;
  
  @if $value > 1 {
    @warn 'Invalid input.';
    @return false;
  }
  
  @if abs($value) > 1/sqrt(2) {
    $flag: 1;
    $sign: $value/abs($value);
    $value: sqrt(1 - pow($value, 2));
  }
  
  $sum: $sum + $coeff*$value;
  
  @for $i from 1 through $precision {
    $coeff: $coeff*(2*$i - 1)/(2*$i);
    $sum: $sum + $coeff*pow($value, 2*$i + 1)/(2*$i + 1);
  }
  
  $result: $sign*($flag*pi()/2 + pow(-1, $flag)*$sum);
  
  @if $unit != '' {
    $result: convert-angle($result, $unit);
  }
  
  @return $result;
}

@function acos($value, $unit: 'rad', $precision: 25) {
  $result: pi()/2 - asin($value, '', $precision);
  
  @if $unit != '' {
    $result: convert-angle($result, $unit);
  }
  
  @return $result;
}

@function atan($value, $unit: 'rad', $precision: 25) {
  $value: $value/sqrt(1 + pow($value, 2));
  
  @return asin($value, $unit, $precision);
}

// COMPUTED STUFF
$d2: $a*sqrt(2); // big diagonal of rhombus
$l: $a*sqrt(3)/2; // side of rhombus
$hp: $d2/2; // pyramid height
$hr: 2*$a/sqrt(6); // distance between opposite sides of rhombus

$va: 2*atan(($a/2)/($d2/2)); // acute angle of rhombus
$oa: $pi - $va; // obtuse angle of rhombus
$sa: $pi/2 - $va; // skew angle
$sf: cosu($sa); // scale factor after skew
$da: $pi/3; // dihedral angle
$pa: asin(($a/2)/$l, 'rad');

// mixin for central positioning
@mixin size-pos($w, $h: $w) {
  @if $w != $h { margin: -$h/2 (-$w/2); }
  @else { margin: -$w/2; }
  width: $w; height: $h;
}

html, body {
  overflow: hidden;
  margin: 0;
  height: 100%;
  perspective: 25em;
  background: dimgrey;
}

.polyhedron, .polyhedron *, .polyhedron *:before {
  position: absolute;
  top: 50%; left: 50%;
  transform-style: preserve-3d;
}
.polyhedron--rhombic-dodecahedron {
  transform: rotateY(-45deg) rotateX(15deg);
  animation: rot $tr linear infinite;
}
@keyframes rot {
  to { transform: rotateY(315deg) rotateX(15deg); }
}

@for $i from 0 to $n {
  $ra: (1 - pow(-1, floor($i/2)%2))*$pi/2 + pow(-1, $i)*$va/2;
  $rot: if($i%6 < 4, 
    'rotateY(#{$ra}) rotateX(#{$da}) rotateY(#{$ra})', 
    'rotate(#{(1 - pow(-1, $i%2))*$pi/4})');
  .piece:nth-child(#{$i + 1}) {
    transform: 
      rotate((1 - pow(-1, floor($i/6)))*$pi/2) 
      unquote($rot) 
      translateY($d2/2);
    animation: ani#{$i + 1} ($te) linear infinite alternate;
    .face--base-rhombus {
      $c: rgba(nth($shades, $i + 1), $of);
      background: linear-gradient(-45deg, 
          lighten($c, 15%), darken($c, 15%), lighten($c, 15%));
    }
    @for $j from 0 to 4 {
      .face--lateral-triangle:nth-child(#{$j + 1}):before {
        $c: rgba(yellow, $of);
        $c2: rgba(darkorange, $of);
        background: linear-gradient(random(360)*1deg, $c, $c2);
      }
    }
  }
  @keyframes ani#{$i + 1} {
    0%, 20% {
      transform: 
        rotate((1 - pow(-1, floor($i/6)))*$pi/2) 
        unquote($rot) 
        translateY($d2/2);
    }
    40% {
      transform: 
        rotate((1 - pow(-1, floor($i/6)))*$pi/2) 
        unquote($rot) 
        translateY($d2);
    }
    60% {
      transform: 
        rotate((1 - pow(-1, floor($i/6)))*$pi/2) 
        unquote($rot) 
        translateY($d2) 
        rotateX($pi);
    }
    80%, 100% {
      transform: 
        rotate((1 - pow(-1, floor($i/6)))*$pi/2) 
        unquote($rot) 
        translateY($d2) 
        rotateX($pi) 
        translateY($d2/2);
    }
  }
}

.face {
  @include size-pos($l);
  backface-visibility: hidden;
}
.face--lateral-triangle {
  overflow: hidden;
  transform-origin: 50% 100%;
  @for $i from 0 to 4 {
    &:nth-child(#{$i + 1}) {
      $ra: (1 - pow(-1, floor($i/2)%2))*pi()/2*1rad + 
           pow(-1, $i)*$va/2;
      box-shadow: inset pow(-1, $i)*.0625em -.125em $bc;
      transform: 
        translateY(-$l/2) 
        rotateY($ra) 
        translateZ($hr/2) 
        translateX(pow(-1, $i)*$l/2*sinu($sa)) 
        rotateX($pi/2 - $da) 
        skewX(pow(-1, $i + 1)*$sa) 
        scaleY($sf);
      &:before {
        @include size-pos($a);
        transform: scaleY(1/$sf) 
                   skewX(pow(-1, $i)*$sa) 
                   rotate(pow(-1, $i + 1)*(pi()*1rad/2 - $oa/2)) 
                   translateX(pow(-1, $i + 1)*50%);
        box-shadow: 
          inset pow(-1, $i + 1)*.0625em 0 rgba($bc, 1 - $of);
        background: hsla(random(360), 100%, 50%, .2);
        content: '';
      }
    }
  }
}
.face--base-rhombus {
  transform: 
    rotateX(-$pi/2)
    rotate(-$va/2) 
    skewX($sa) 
    scaleY($sf);
    box-shadow: inset 0 0 0 .0625em $bc;
    background: hsla(random(360), 100%, 50%, .2);
}
            
          
!
            
              // Only tested in Chrome & Firefox
// Yup, pure CSS. No JS here
            
          
!
999px
Loading ..................

Console