-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f900c2
commit ec2354a
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const targetColors = [ | ||
"#101004", | ||
"#401010", | ||
"#104010", | ||
"#101040", | ||
"#041010", | ||
"#100410", | ||
]; | ||
const cycleTime = 5_000; // ms | ||
|
||
// TODO: This is AI generated, I should probably make my own | ||
const targetElement = document.getElementById("gradient"); | ||
|
||
function tick() { | ||
const now = Date.now(); | ||
const cycle = Math.floor(now / cycleTime) % targetColors.length; | ||
const cycleProgress = (now % cycleTime) / cycleTime; | ||
|
||
const startColor = targetColors[cycle]; | ||
const endColor = targetColors[(cycle + 1) % targetColors.length]; | ||
|
||
const r1 = parseInt(startColor.substring(1, 3), 16); | ||
const g1 = parseInt(startColor.substring(3, 5), 16); | ||
const b1 = parseInt(startColor.substring(5, 7), 16); | ||
|
||
const r2 = parseInt(endColor.substring(1, 3), 16); | ||
const g2 = parseInt(endColor.substring(3, 5), 16); | ||
const b2 = parseInt(endColor.substring(5, 7), 16); | ||
|
||
const r = Math.floor(r1 + (r2 - r1) * cycleProgress); | ||
const g = Math.floor(g1 + (g2 - g1) * cycleProgress); | ||
const b = Math.floor(b1 + (b2 - b1) * cycleProgress); | ||
|
||
targetElement.style.backgroundColor = `rgb(${r}, ${g}, ${b})`; | ||
|
||
requestAnimationFrame(tick); | ||
} | ||
|
||
requestAnimationFrame(tick); |
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