Created
February 9, 2017 09:31
-
-
Save IvanofSA/768e874828319307a9d29b5f6e26a100 to your computer and use it in GitHub Desktop.
changeBackground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colors = new Array( | |
[58,96,115], | |
[22,34,42], | |
[0, 22, 8], | |
[38,56,35], | |
[32,24,82], | |
[135, 129, 19] | |
); | |
var step = 0; | |
var colorIndices = [0,1,2,3]; | |
var gradientSpeed = 0.002; | |
function updateGradient() { | |
if ( $===undefined ) return; | |
var c0_0 = colors[colorIndices[0]]; | |
var c0_1 = colors[colorIndices[1]]; | |
var c1_0 = colors[colorIndices[2]]; | |
var c1_1 = colors[colorIndices[3]]; | |
var istep = 1 - step; | |
var r1 = Math.round(istep * c0_0[0] + step * c0_1[0]); | |
var g1 = Math.round(istep * c0_0[1] + step * c0_1[1]); | |
var b1 = Math.round(istep * c0_0[2] + step * c0_1[2]); | |
var color1 = "rgb("+r1+","+g1+","+b1+")"; | |
var r2 = Math.round(istep * c1_0[0] + step * c1_1[0]); | |
var g2 = Math.round(istep * c1_0[1] + step * c1_1[1]); | |
var b2 = Math.round(istep * c1_0[2] + step * c1_1[2]); | |
var color2 = "rgb("+r2+","+g2+","+b2+")"; | |
$('body').css({ | |
background: "-webkit-gradient(linear, left top, right top, from("+color1+"), to("+color2+"))"}).css({ | |
background: "-moz-linear-gradient(left, "+color1+" 0%, "+color2+" 100%)"}); | |
step += gradientSpeed; | |
if ( step >= 1 ) | |
{ | |
step %= 1; | |
colorIndices[0] = colorIndices[1]; | |
colorIndices[2] = colorIndices[3]; | |
colorIndices[1] = ( colorIndices[1] + Math.floor( 1 + Math.random() * (colors.length - 1))) % colors.length; | |
colorIndices[3] = ( colorIndices[3] + Math.floor( 1 + Math.random() * (colors.length - 1))) % colors.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment