11import App from "./components/App" ;
2+
3+
4+ var colors = new Array (
5+ [ 62 , 35 , 255 ] ,
6+ [ 60 , 255 , 60 ] ,
7+ [ 255 , 35 , 98 ] ,
8+ [ 45 , 175 , 230 ] ,
9+ [ 255 , 0 , 255 ] ,
10+ [ 255 , 128 , 0 ] ) ;
11+
12+ var step = 0 ;
13+ //color table indices for:
14+ // current color left
15+ // next color left
16+ // current color right
17+ // next color right
18+ var colorIndices = [ 0 , 1 , 2 , 3 ] ;
19+
20+ //transition speed
21+ var gradientSpeed = 0.002 ;
22+
23+ function updateGradient ( )
24+ {
25+
26+ if ( $ === undefined ) return ;
27+
28+ var c0_0 = colors [ colorIndices [ 0 ] ] ;
29+ var c0_1 = colors [ colorIndices [ 1 ] ] ;
30+ var c1_0 = colors [ colorIndices [ 2 ] ] ;
31+ var c1_1 = colors [ colorIndices [ 3 ] ] ;
32+
33+ var istep = 1 - step ;
34+ var r1 = Math . round ( istep * c0_0 [ 0 ] + step * c0_1 [ 0 ] ) ;
35+ var g1 = Math . round ( istep * c0_0 [ 1 ] + step * c0_1 [ 1 ] ) ;
36+ var b1 = Math . round ( istep * c0_0 [ 2 ] + step * c0_1 [ 2 ] ) ;
37+ var color1 = "rgb(" + r1 + "," + g1 + "," + b1 + ")" ;
38+
39+ var r2 = Math . round ( istep * c1_0 [ 0 ] + step * c1_1 [ 0 ] ) ;
40+ var g2 = Math . round ( istep * c1_0 [ 1 ] + step * c1_1 [ 1 ] ) ;
41+ var b2 = Math . round ( istep * c1_0 [ 2 ] + step * c1_1 [ 2 ] ) ;
42+ var color2 = "rgb(" + r2 + "," + g2 + "," + b2 + ")" ;
43+
44+ $ ( '#gradient' ) . css ( {
45+ background : "-webkit-gradient(linear, left top, right top, from(" + color1 + "), to(" + color2 + "))" } ) . css ( {
46+ background : "-moz-linear-gradient(left, " + color1 + " 0%, " + color2 + " 100%)" } ) ;
47+
48+ step += gradientSpeed ;
49+ if ( step >= 1 )
50+ {
51+ step %= 1 ;
52+ colorIndices [ 0 ] = colorIndices [ 1 ] ;
53+ colorIndices [ 2 ] = colorIndices [ 3 ] ;
54+
55+ //pick two new target color indices
56+ //do not pick the same as the current one
57+ colorIndices [ 1 ] = ( colorIndices [ 1 ] + Math . floor ( 1 + Math . random ( ) * ( colors . length - 1 ) ) ) % colors . length ;
58+ colorIndices [ 3 ] = ( colorIndices [ 3 ] + Math . floor ( 1 + Math . random ( ) * ( colors . length - 1 ) ) ) % colors . length ;
59+
60+ }
61+ }
62+
63+ setInterval ( updateGradient , 10 ) ;
0 commit comments