Skip to content

Commit c0aa186

Browse files
authored
Merge pull request #10 from techwithtim/coloredBackground
make background change color
2 parents 474dd49 + daf354b commit c0aa186

File tree

7 files changed

+115
-5
lines changed

7 files changed

+115
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.node
2-
/__pycahce__
2+
node_modules/
3+
__pycache__/
4+

Tutorial 17/db.sqlite3

0 Bytes
Binary file not shown.

Tutorial 17/frontend/src/index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
11
import 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);

Tutorial 17/frontend/static/css/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ body {
2424
left: 50%;
2525
transform: translate(-50%, -50%);
2626
}
27+
28+
#gradient {
29+
width: 100%;
30+
height: 800px;
31+
padding: 0px;
32+
margin: 0px;
33+
}

Tutorial 17/frontend/static/frontend/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tutorial 17/frontend/static/frontend/main.js.LICENSE.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 10:121-141 */
2+
3+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 11:504-524 */
4+
5+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 12:312-332 */
6+
7+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 13:15-35 */
8+
9+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 16:248-268 */
10+
11+
/*! CommonJS bailout: exports.unstable_now(...) prevents optimization as exports is passed as call context at 19:56-76 */
12+
13+
/*! CommonJS bailout: exports.unstable_shouldYield(...) prevents optimization as exports is passed as call context at 16:106-134 */
14+
15+
/*! CommonJS bailout: module.exports is used directly at 103:0-14 */
16+
17+
/*! CommonJS bailout: module.exports is used directly at 12:0-14 */
18+
19+
/*! CommonJS bailout: module.exports is used directly at 16:0-14 */
20+
21+
/*! CommonJS bailout: module.exports is used directly at 17:0-14 */
22+
23+
/*! CommonJS bailout: module.exports is used directly at 18:2-16 */
24+
25+
/*! CommonJS bailout: module.exports is used directly at 1:0-14 */
26+
27+
/*! CommonJS bailout: module.exports is used directly at 55:0-14 */
28+
29+
/*! CommonJS bailout: module.exports is used directly at 5:4-18 */
30+
31+
/*! CommonJS bailout: module.exports is used directly at 65:0-14 */
32+
33+
/*! CommonJS bailout: module.exports is used directly at 6:0-14 */
34+
35+
/*! CommonJS bailout: module.exports is used directly at 7:0-14 */
36+
37+
/*! CommonJS bailout: module.exports is used directly at 9:4-18 */
38+
139
/*! default exports */
240

341
/*! dynamic exports */

Tutorial 17/frontend/templates/frontend/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
/>
1515
</head>
1616
<body>
17-
<div id="main">
18-
<div id="app"></div>
17+
<div id="gradient">
18+
<div id="main">
19+
<div id="app"></div>
20+
</div>
1921
</div>
20-
2122
<script src="{% static "frontend/main.js" %}"></script>
2223
</body>
2324
</html>

0 commit comments

Comments
 (0)