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 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

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.

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

              
                - const nbPlanets = 10;

.cosmos
  .galaxy
    - for ( let i = 0; i < nbPlanets; i++ )
      .box
        .planet
          .cube
            .face
            .face
        .orbit
              
            
!

CSS

              
                // Variables

$baseSize: 2vw;
$baseTimeOrbit: 3s;
$baseTimeRotation: 4s;

$colorGalaxy: #212121;
$colorOrbit: #323232;
$colorOrbitBefore: #0d7377;
$colorOrbitAfter: #14ffec;
  
$ratioBackground: .25;
$ratioBorder: .05;
$ratioShadow: .25;
$ratioOrbit: .1;

$darken: 10%;
$lighten: 20%;

$perspective: 100vw;

// distance, ratioSize, ratioTimeOrbit, ratioTimeRotation, color, transform
$planets: (
  ( 0, 4, 5, 6, #ffd700, ( 1, 1, 1 ) ),
  ( 2.5, .5, .5, .8, #b5592a, ( 1, 0, 0 ) ), 
  ( 2, .6, .3, .4, #774181, ( 0, 1, 0 ) ), 
  ( 1.6, 1, 1, 1, #00d1ff, ( 0, 0, 1 ) ), 
  ( 2.4, .8, 2, 1.5, #17b978, ( 1, 1, 0 ) ), 
  ( 1.2, .65, 4, 3, #b74242, ( 1, 0, 1 ) ), 
  ( 2, 1.25, 2, 2, #fd5f00, ( -1, 0, 0 ) ), 
  ( 3.2, 1.3, .6, 2, #38598b, ( 0, 1, 1 ) ),
  ( 2, .6, .8, 1, #ff78ae, ( 0, -1, -1 ) ),
  ( 1.5, .5, 4, 3, #7b77ff, ( 0, 1, -1 ) ),
);

// Extends

%center
{
  display: flex;
  align-items: center;
  justify-content: center;
}

// Mixins

@mixin position ( $position )
{
  left: $position;
  transform-origin: -$position;  
}

@mixin orbit ( $size, $distance )
{
  $orbitBorder: $size * $ratioOrbit;
  $orbitSize: $distance * 2 + $orbitBorder;
  $orbitDistance: 2 * $orbitBorder;
  $orbitSizeBefore: $orbitSize - $orbitDistance;
  $orbitSizeAfter: $orbitSize + $orbitDistance;
  
  & + .orbit
  {
    width: $orbitSize;
    height: $orbitSize;
    
    &,
    &::before,
    &::after
    {
      border-width: $orbitBorder;
    }
    
    &::before
    {
      width: $orbitSizeBefore;
      height: $orbitSizeBefore;
    }

    &::after
    {
      width: $orbitSizeAfter;
      height: $orbitSizeAfter;
    }
  }
}

// Cube colors

@mixin skin ( $size, $color )
{
  $colorShadow: lighten( $color, $lighten);
  $colorBorder: darken( $color, $darken );
  
  $sizeShadow: $size * $ratioShadow;
  $boxShadow: 0 0 $sizeShadow $sizeShadow * .25 $colorShadow inset;
     
  &,
  &::before,
  &::after
  {
    background-color: rgba( $color, $ratioBackground );
    border: $size * $ratioBorder solid $colorBorder;
    box-shadow: $boxShadow;
  }
}

// Cube

@mixin cube ( $size )
{
  width: $size;
  height: $size;
}

// Cube faces

@mixin cubeFaces ( $half )
{
  &:first-child
  {
    & { transform: rotate3d( 0, 1, 0, 0deg ) translate3d( 0, 0, $half ) }
    &::before { transform: rotate3d( 0, 1, 0, 90deg ) translate3d( $half, 0, $half ) }
    &::after { transform: rotate3d( 0, 1, 0, -90deg ) translate3d( -$half, 0, $half ) }
  }

  &:last-child
  {
    & { transform: rotate3d( 0, 1, 0, 180deg ) translate3d( 0, 0, $half ) }
    &::before { transform: rotate3d( 1, 0, 0, 90deg ) translate3d( 0, -$half, $half ) }
    &::after { transform: rotate3d( 1, 0, 0, -90deg ) translate3d( 0, $half, $half ) }
  }
}

// Cube animation

@mixin cubeAnimation ( $timeAnimation, $transform )
{
  animation-duration: $timeAnimation;
    
  @keyframes rotation
  {
    100% { transform: rotate3d( $transform, 360deg ) }
  }
}

// Galaxy animation

@mixin galaxyAnimation ( 
  $duration: 10s, 
  $distance: 5vw, 
  $angle: 45deg,
  $animated: true,
  $reversed: false,
)
{
  $direction: if( $reversed, 1, -1 );
  
  $distance: $direction * $distance;
  $angle: $direction * $angle;
  
  @if $animated
  {
    animation: galaxy infinite ease-in-out alternate $duration;
    
    @keyframes galaxy
    {
      0% { transform: translate3d( 0, $distance, 0 ) rotate3d( 1, 1, 1, $angle ) }
      100% { transform: translate3d( 0, -$distance, 0 ) rotate3d( 1, 1, 1, -$angle ) }
    }
  }
  @else
  {
    transform: translate3d( 0, $distance, 0 ) rotate3d( 1, 1, 0, $angle );
  }
}

// Planet

@mixin planets ( 
  $planets, 
  $baseSize: 5vw, 
  $baseTimeOrbit: 5s, 
  $baseTimeRotation: 5s 
)
{
  $index: 1;
  
  $prevDistance: 0;
  
  @each 
    $distance, 
    $ratioSize, 
    $ratioTimeOrbit, 
    $ratioTimeRotation, 
    $color, 
    $transform 
  in $planets
  {
    $size: $baseSize * $ratioSize;
    $half: $size / 2;
     
    $nextDistance: $prevDistance + $distance + $half;
    
    $currentDistance: if( $index == 1, 0, $nextDistance );
    
    .box:nth-of-type( #{ $index } )
    {
      .planet
      {
        @include position( $currentDistance );
        
        animation-duration: $ratioTimeOrbit * $baseTimeOrbit;
        
        .cube
        {
          @include cube( $size );
          @include cubeAnimation( 
            $ratioTimeRotation * $baseTimeRotation, 
            $transform 
          );
        }
        
        .face
        {
          @include cubeFaces( $half );
          @include skin( $size, $color );
        }
        
        @if $index > 1
        {
          @include orbit( $size, $currentDistance );
        }
      }
    }
    
    $index: $index + 1;
    $prevDistance: $currentDistance + $half;
  }
}

// Reset

*,
*::before,
*::after
{
  outline: 0;
  margin: 0;
  border: 0;
  padding: 0;
  box-sizing: border-box;
}

// Layout

html
{
  width: 100vw;
  height: 100vh;
}

body
{
  width: 100%;
  height: 100%;
}

.planet,
.cube,
.face
{
  @extend %center;
  position: absolute;
  transform-style: preserve-3d;
}

// Cosmos

.cosmos
{
  @extend %center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  perspective: $perspective;
  background-color: $colorGalaxy;
}

// Galaxy

.galaxy
{
  // Planets 
  @include planets( $planets, $baseSize );
  
  @include galaxyAnimation();
  
  transform-style: preserve-3d;
}

// Box

.box
{
  @extend %center;
}

.planet
{
  animation: orbit infinite linear;
}

// Orbit

.orbit
{
  @extend %center;  
  transform: rotate3d( 1, 0, 0, 90deg );
  
  &,
  &::before,
  &::after
  {
    position: absolute;
    border-radius: 50%;
    border-style: solid;
  }
  
  &::before,
  &::after
  {
    content: '';
  }
  
  &
  {
    border-color: $colorOrbit;
  }
  
  &::before
  {
    border-color: $colorOrbitBefore;
  }
  
  &::after
  {
    border-color: $colorOrbitAfter;
  }
}

// Cube

.cube
{
  animation: rotation infinite linear;
}

// Cube face

.face
{   
  &,
  &::before,
  &::after
  {
    width: 100%;
    height: 100%;
  }

  &::before,
  &::after
  {    
    content: '';
    position: absolute;
    box-sizing: content-box;
  }
}

// Animations

@keyframes orbit
{
  100% { transform: rotate3d( 0, 1, 0, 360deg ) }
}
              
            
!

JS

              
                
              
            
!
999px

Console