Skip to content

Commit 829b8f9

Browse files
committed
Attempt #1
1 parent f90f41f commit 829b8f9

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

src/App.css

+11
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@
99
margin: 0 auto;
1010
padding: 0 2rem;
1111
}
12+
13+
canvas {
14+
width: 100%;
15+
height: 100%;
16+
position: fixed;
17+
top: 0;
18+
bottom: 0;
19+
z-index: -1;
20+
aspect-ratio: auto 1920 / 948;
21+
opacity: 0.5;
22+
}

src/App.js

+49
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,59 @@ class App extends Component {
1717
<Route path="/about" component={AboutMe} />
1818
<Route path="/goals" component={OKRPage} />
1919
</Switch>
20+
<BackgroundCanvas />
2021
</div>
2122
</BrowserRouter>
2223
);
2324
}
2425
}
2526

27+
function BackgroundCanvas() {
28+
const canvasRef = React.useRef(null);
29+
30+
React.useEffect(() => {
31+
const canvas = canvasRef.current;
32+
const context = canvas.getContext('2d');
33+
let time = 0;
34+
let animationFrameId;
35+
36+
const color = function (x, y, r, g, b) {
37+
context.fillStyle = `rgb(${r}, ${g}, ${b})`;
38+
context.fillRect(x, y, 1, 1);
39+
}
40+
41+
const R = function (x, y, time) {
42+
return (Math.floor(192 + 64 * Math.cos((x * x - y * y) / 300 + time)));
43+
}
44+
45+
const G = function (x, y, time) {
46+
return (Math.floor(192 + 64 * Math.sin((x * x * Math.cos(time / 4) + y * y * Math.sin(time / 3)) / 300)));
47+
}
48+
49+
const B = function (x, y, time) {
50+
return (Math.floor(192 + 64 * Math.sin(5 * Math.sin(time / 9) + ((x - 100) * (x - 100) + (y - 100) * (y - 100)) / 1100)));
51+
}
52+
53+
const startAnimation = function () {
54+
for (let x = 0; x <= 30; x++) {
55+
for (let y = 0; y <= 30; y++) {
56+
color(x, y, R(x, y, time), G(x, y, time), B(x, y, time));
57+
}
58+
}
59+
time = time + 0.120;
60+
animationFrameId = window.requestAnimationFrame(startAnimation);
61+
}
62+
startAnimation()
63+
64+
return () => {
65+
window.cancelAnimationFrame(animationFrameId)
66+
}
67+
}, []);
68+
69+
return (
70+
<canvas ref={canvasRef} className="background-gradient" width="32" height="32"></canvas>
71+
);
72+
}
73+
2674
export default App;
75+

src/index.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ body {
2222
-webkit-font-smoothing: antialiased;
2323
-moz-osx-font-smoothing: grayscale;
2424
background-color: #f4f9f9;
25-
}
25+
}

src/pages/OKRPage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ function OKRPage() {
143143
<KeyResultList>
144144
<KeyResultListItem
145145
label="180km Cycling"
146-
progress={{ current: 17, target: 180, unit: "km" }}
146+
progress={{ current: 30.5, target: 180, unit: "km" }}
147147
showProgress={showProgress}
148148
/>
149149
<KeyResultListItem
150150
label="180km Walking"
151-
progress={{ current: 50, target: 180, unit: "km" }}
151+
progress={{ current: 89, target: 180, unit: "km" }}
152152
showProgress={showProgress}
153153
/>
154154
<KeyResultListItem

0 commit comments

Comments
 (0)