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

              
                div
  svg(width="600" height="600" viewBox="0 0 600 600")
              
            
!

CSS

              
                html, body { 
  height: 100%; 
}

body {
  background: grey;
  display: flex;
  align-items: center;
  justify-content: center;
}

svg {
  background: white;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                
/* Noel Delgado | @pixelia_me */

var svgElement = document.querySelector('svg');
var SIZE = svgElement.width.baseVal.value;
var THIRD = (SIZE/3);
var DURATION = 8000;
var D3 = DURATION/3;
var D4 = DURATION/4;
var D5 = DURATION/5;
var D8 = DURATION/8;
var D10 = DURATION/10;
var TOTAL_STARS = 30;
var STARS = [];

/* SVG setup */
var paper = Snap(svgElement);
var landscape = paper.g();
var bgGradient = paper.gradient('l(0,0,0,2)#2552BD-#F5679B');

/* Start adding the svg elements */
var background = paper.rect(0,0,SIZE,SIZE).attr({ fill: bgGradient });
landscape.add(background);

for (var i = 0; i < TOTAL_STARS; i++) {
  var star = paper.circle(0,0,1).attr({fill : '#fff', opacity : Math.random()});
  landscape.add(star);
  STARS.push(star);
}

var moon = paper.path('M315.001746,134.998584 C321.072986,139.559126 325,146.819897 325,155 C325,168.807119 313.810155,180 300,180 C291.820962,180 284.559291,176.073348 279.998254,170.001416 C284.176856,173.140262 289.371187,175 295,175 C308.810155,175 320,163.807119 320,150 C320,144.370682 318.140242,139.176743 315.001746,134.998584 Z').attr({
  fill : '#fff'
}).transform('t0,0');
landscape.add(moon);

var mountain4 = paper.group(
  paper.polygon(300,0,600,250,0,250).transform('t-50,220'),
  paper.polygon(300,0,600,210,70,210).transform('t70,260')
).attr({
  fill: '#263653',
  opacity: 0.1
});
landscape.add(mountain4);

var mountain3 = paper.group(
  paper.polygon(300,0,630,145,50,145).transform('t-96,342'),
  paper.polygon(6,0,12,20,0,20).transform('t255,355'),
  paper.polygon(6,0,12,20,0,20).transform('t260,360'),
  paper.polygon(6,0,12,20,0,20).transform('t270,365'),
  paper.polygon(6,0,12,20,0,20).transform('t286,372')
).attr({
  fill: '#192A49'
});
landscape.add(mountain3);

var mountain2 = paper.g(
  paper.path('M0 220 C 180 130, 300, 80, 600, 0 V 220 Z'),
  paper.polygon(6,0,12,20,0,20).transform('t366,58'),
  paper.polygon(6,0,12,20,0,20).transform('t386,48'),
  paper.polygon(6,0,12,20,0,20).transform('t402,48'),
  paper.polygon(6,0,12,20,0,20).transform('t426,38'),
  paper.polygon(10,0,20,40,0,40).transform('t452,6'),
  paper.polygon(6,0,12,20,0,20).transform('t476,24'),
  paper.polygon(6,0,12,20,0,20).transform('t496,10'),
  paper.polygon(34,0,68,140,0,140).transform('t524,-110')
).attr({
  fill: '#0D1F3F'
}).transform('t0,380');
landscape.add(mountain2);

var mountain1 = paper.g(
  paper.path('M0 220 C 180 130, 300, 80, 600, 0 V 220 Z').transform('s-1,1,300,110'),
  paper.polygon(34,0,76,180,0,160).transform('t12,-150'),
  paper.polygon(34,0,72,86,0,70).transform('t92,-40'),
  paper.polygon(20,0,30,32,10,26).transform('t170,26')
).attr({
  fill: '#001335'
}).transform('t0,380');
landscape.add(mountain1);

var shadow = paper.rect(0,0,SIZE,SIZE);
landscape.add(shadow);

var clippath = paper.rect(THIRD, THIRD, THIRD,THIRD).attr({fill: '#000'});
landscape.attr({clipPath: clippath});


/*****************************************************************************
 * animations
 ****************************************************************************/
function animateStar(el) {
  el.animate({
    opacity: Math.random(),
    cx: el.getBBox().cx + 4
  }, D10, mina.linear, function() {
    animateStar(el);
  });
}

// 1. show the landscape
function animation1() {
  shadow.animate({opacity: 0}, D5);

  clippath.animate({
    x: 0, y: 0,
    width: SIZE,
    height: SIZE,
    transform : 'r90,300,300'
  }, D5, mina.backin, animation2);
}

// 2. sunrising
function animation2() {
  moon.animate({transform: 't0,0'}, D3, mina.elastic);
  moon.animate({opacity: 0.5}, DURATION, mina.linear);
  mountain1.animate({transform:'t-20,420'}, DURATION + (D3));
  mountain2.animate({transform:'t20,420'}, DURATION + (D3));
  mountain3.animate({transform:'t-20,40'}, DURATION + (D3));
  mountain4.animate({transform:'t20,40'}, DURATION + (D3));
  bgGradient.animate({x1: 0, y1: 0, x2: 0, y2: 1}, DURATION, mina.linear, animation3);
  STARS.forEach(animateStar);
}

// 3. getting ready to hide the landscape
function animation3() {
  moon.animate({transform: 't0,-200'}, D8, mina.backin, animation4);
}

// 4. back to black square
function animation4() {
  shadow.animate({opacity: 1}, D4);

  clippath.animate({
    x: THIRD, y: THIRD,
    width: THIRD,
    height: THIRD,
    transform : 'r180,300,300'
  }, D4, mina.bounce, animation0);
}

// start the thing/reset : wait 1sec before starting : loop
function animation0() {
  bgGradient.attr({x1: 0, y1: 0, x2: 0, y2: 2});
  moon.attr({opacity: 1});
  STARS.forEach(function(s) {s.stop();});
  mountain1.attr({transform:'t0,380'});
  mountain2.attr({transform:'t0,380'});
  mountain3.attr({transform:'t0,0'});
  mountain4.attr({transform:'t0,0'});
  clippath.attr({transform: 'r0,0,0'});

  STARS.forEach(function(star) {
    var cx = ~~(Math.random() * (SIZE-20)) + 20;
    var cy = ~~(Math.random() * 160) + 20;
    var r = Math.random() * 1.5;
    star.attr({cx: 0, cy: 0, r: 0});
    star.attr({cx: cx, cy: cy, r: r});
  });

  window.setTimeout(animation1, 1000);
}

animation0();
              
            
!
999px

Console