Skip to content

Commit

Permalink
Added leaves widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nothans committed Oct 31, 2024
1 parent 1fe48e6 commit 44e7714
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 10 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ This widget displays the background color set to the latest CheerLights color.

> [Solid Color Background CheerLights Widget](https://widgets.cheerlights.com/color.html)
## CheerLights Logo
This widget displays the CheerLights logo with a background color that changes to the current CheerLights color.

> [CheerLights Logo CheerLights Widget](https://widgets.cheerlights.com/logo.html)
## FearLights Logo
This widget displays the FearLights logo with a background color that changes to the current CheerLights color. This is a Halloween-themed widget.

> [FearLights Logo CheerLights Widget](https://widgets.cheerlights.com/fearlights.html)
## Snow
This widget displays falling snowflakes using the CheerLights JavaScript library.

> [Snow CheerLights Widget](https://widgets.cheerlights.com/snow.html)
## Leaves
This widget displays falling leaves using the CheerLights JavaScript library.

> [Leaves CheerLights Widget](https://widgets.cheerlights.com/leaves.html)
## Aurora
This widget displays a dynamic aurora inspired by the current CheerLights color.

Expand All @@ -21,16 +36,6 @@ This widget displays a particle effect inspired by the current CheerLights color

> [Particle CheerLights Widget](https://widgets.cheerlights.com/particle.html)
## CheerLights Logo
This widget displays the CheerLights logo with a background color that changes to the current CheerLights color.

> [CheerLights Logo CheerLights Widget](https://widgets.cheerlights.com/logo.html)
## FearLights Logo
This widget displays the FearLights logo with a background color that changes to the current CheerLights color. This is a Halloween-themed widget.

> [FearLights Logo CheerLights Widget](https://widgets.cheerlights.com/fearlights.html)
## Embed CheerLights Widgets on a Home Assistant Dashboard

To embed CheerLights widgets on a Home Assistant dashboard, follow these steps:
Expand Down
95 changes: 95 additions & 0 deletions leaves.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/png" href="assets/images/CheerLights-Icon.png">

<title>CheerLights JavaScript Widget - Leaves</title>
<meta name="description" content="A widget that displays falling leaves using the CheerLights JavaScript library." />

<style>
body {
cursor: pointer;
height: 100vh;
margin: 0;
overflow: hidden;
position: relative;
}

.leaf {
position: fixed;
top: -10px;
user-select: none;
cursor: default;
animation: fall linear forwards;
}

@keyframes fall {
0% {
transform: translateY(0) translateX(0) rotate(0deg);
}
25% {
transform: translateY(25vh) translateX(10vw) rotate(15deg);
}
50% {
transform: translateY(50vh) translateX(-10vw) rotate(-15deg);
}
75% {
transform: translateY(75vh) translateX(10vw) rotate(10deg);
}
100% {
transform: translateY(100vh) translateX(0) rotate(0deg);
}
}
</style>
</head>

<body>
<script src="https://cdn.jsdelivr.net/gh/cheerlights/[email protected]/cheerlights.js"></script>

<script>
const REFRESH_INTERVAL = 5000;
const CHEERLIGHTS_URL = 'https://cheerlights.com/cheerlights-javascript-widgets/';

CheerLights.getColor(setBodyBackgroundColor);

setInterval(() => CheerLights.getColor(setBodyBackgroundColor), REFRESH_INTERVAL);

function setBodyBackgroundColor(color) {
if (!color || !color.htmlName) {
console.error('Invalid color data received');
return;
}
document.body.style.backgroundColor = color.htmlName;
document.body.title = `Current CheerLights color: ${color.htmlName}`;
}

function createLeaf() {
const leaf = document.createElement('div');
leaf.className = 'leaf';
leaf.style.left = Math.random() * 100 + '%';
leaf.style.animationDuration = Math.random() * 5 + 5 + 's';
leaf.style.fontSize = Math.random() * 60 + 10 + 'px';
leaf.style.opacity = Math.random() * 0.5 + 0.5;

const leaves = ['🍂', '🍁'];
leaf.innerHTML = leaves[Math.floor(Math.random() * leaves.length)];

leaf.addEventListener('animationend', () => {
leaf.remove();
});

document.body.appendChild(leaf);
}

setInterval(createLeaf, 300);

document.body.addEventListener('click', () => {
window.open(CHEERLIGHTS_URL, '_blank');
});
</script>

</body>
</html>

0 comments on commit 44e7714

Please sign in to comment.