Skip to content

Instantly share code, notes, and snippets.

@HelloWorld017
Created February 7, 2017 10:49
Show Gist options
  • Save HelloWorld017/6fb557767095a0e79140cb3bfbed83e7 to your computer and use it in GitHub Desktop.
Save HelloWorld017/6fb557767095a0e79140cb3bfbed83e7 to your computer and use it in GitHub Desktop.
Automated changing flat stripe background for ghost.
(function(){
//SVG Flat Stripe Background
//by Khinenw
//gist.github.com/HelloWorld017/6fb557767095a0e79140cb3bfbed83e7
'use strict';
if(location.pathname !== '/') return;
var themes = [[/^\d+-(02|03|04)-.+$/, ['#f8bbd0', '#f06292', '#e91e63', '#c2185b', '#880e4f']], //Haru
[/^\d+-(05|06|07)-.+$/, ['#ffeb3b', '#cddc39', '#8bc34a', '#4caf50', '#009688']], //Natsu
[/^\d+-(08|09|10)-.+$/, ['#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100']], //Aki
[/^\d+-(11|12|01)-.+$/, ['#e1f5fe', '#4fc3f7', '#03a9f4', '#0288d1', '#01579b']] //Fuyu
];
var fullHeight = 2048;
var fullWidth = 2048;
var stripeCount = 5;
var stripeUnit = fullHeight / stripeCount;
var stripeWidth = 64;
var stripeMinHeight = stripeUnit / 4;
var stripeMaxHeight = stripeUnit / 1.5;
var stripeRadius = 32;
var stripeColors = themes.find(function (v) {
return v[0].test(new Date().toISOString());
})[1];
var path = [];
var buildPath = function buildPath(color) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return '<path fill="' + color + '" d="' + args.map(function (v) {
return v.shift() + ' ' + v.join(',');
}).join(' ') + '"/>';
};
for (var i = 0; i < stripeCount; i++) {
var y = i * stripeUnit;
path.push(buildPath(stripeColors[i], ['M', 0, y], ['L', fullWidth, y], ['L', fullWidth, y + stripeUnit], ['L', 0, y + stripeUnit], ['Z']));
var j = 0;
for (var x = 0; x < fullWidth; x += stripeWidth) {
var randomHeight = Math.floor(Math.random() * (stripeMaxHeight - stripeMinHeight)) + stripeMinHeight;
path.push(buildPath(i === 0 || j % 2 === 0 ? stripeColors[i] : stripeColors[i - 1], ['M', x, y - (randomHeight / 2 - stripeRadius)], ['A',
//x + fullWidth / 2,
//y - (randomHeight / 2 - stripeRadius),
stripeRadius, stripeRadius, 0, 0, 1, x + stripeWidth, y - (randomHeight / 2 - stripeRadius)], ['L', x + stripeWidth, y + (randomHeight / 2 - stripeRadius)], ['A',
//x + fullWidth / 2,
//y + (randomHeight / 2 - stripeRadius),
stripeRadius, stripeRadius, 0, 0, 1, x, y + (randomHeight / 2 - stripeRadius)], ['Z']));
j++;
}
}
var svgString = "url('data:image/svg+xml;base64," + btoa('<svg width="' + fullWidth + '" height="' + fullHeight + '" xmlns="http://www.w3.org/2000/svg">' + path.join('\n') + '</svg>') + "')";
var $ = document.querySelector.bind(document);
var header = $('.main-header');
header.classList.remove('no-cover');
header.style.background = svgString;
jarallax(header, {
speed: 0.5
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment