-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/a11y-custumer-logo
- Loading branch information
Showing
6 changed files
with
243 additions
and
28 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/components/content/heroes/aurora/weather-easter-egg/daylight-percentage-calculator.ts
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,42 @@ | ||
export const getSunlightPercentage = ( | ||
sunriseTime: number, | ||
sunsetTime: number, | ||
time: number, | ||
) => { | ||
const totalDaylightMinutes = sunsetTime - sunriseTime; | ||
if (totalDaylightMinutes <= 0) { | ||
return 20; | ||
} | ||
const currentMinutes = time - sunriseTime; | ||
const sunlightPercentage = (currentMinutes / totalDaylightMinutes) * 100; | ||
|
||
if (sunlightPercentage < 0) { | ||
return 0; | ||
} | ||
if (sunlightPercentage > 100) { | ||
return 100; | ||
} | ||
return Math.round(sunlightPercentage); | ||
}; | ||
|
||
export const getNighttimePercentage = ( | ||
sunriseTime: number, | ||
sunsetTime: number, | ||
time: number, | ||
) => { | ||
const totalDaylightMinutes = sunsetTime - sunriseTime; | ||
const totalNighttimeMinutes = 86400000 - totalDaylightMinutes; | ||
if (totalNighttimeMinutes <= 0) { | ||
return 0; | ||
} | ||
const currentMinutes = time - sunsetTime; | ||
const nighttimePercentage = (currentMinutes / totalNighttimeMinutes) * 100; | ||
|
||
if (nighttimePercentage < 0) { | ||
return 0; | ||
} | ||
if (nighttimePercentage > 100) { | ||
return 100; | ||
} | ||
return Math.round(nighttimePercentage); | ||
}; |
97 changes: 97 additions & 0 deletions
97
src/components/content/heroes/aurora/weather-easter-egg/moon.tsx
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,97 @@ | ||
import styled from 'styled-components'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
interface MoonProps { | ||
nightPercentage: number; | ||
} | ||
|
||
const generateStars = (starCount: number) => { | ||
const stars: React.JSX.Element[] = []; | ||
|
||
for (let i = 0; i < starCount; i++) { | ||
stars.push( | ||
<StarsDiv x={Math.random() * 120 - 10} y={Math.random() * 120 - 10} />, | ||
); | ||
} | ||
|
||
return stars; | ||
}; | ||
|
||
const BackgroundDiv = styled.div<{ nightPercentage: number }>` | ||
position: absolute; | ||
background: #000000; | ||
width: 100%; | ||
height: 100%; | ||
opacity: ${(props) => | ||
props.nightPercentage === 0 || props.nightPercentage === 100 ? '0' : '1'}; | ||
`; | ||
|
||
const StarsDiv = styled.div<{ x: number; y: number }>` | ||
position: absolute; | ||
width: 3px; | ||
height: 3px; | ||
top: ${(props) => props.y}%; | ||
left: ${(props) => props.x}%; | ||
border-radius: 100%; | ||
background: #ffffff; | ||
`; | ||
|
||
const MoonDiv = styled.div<{ nightPercentage: number }>` | ||
position: absolute; | ||
width: 100px; | ||
height: 100px; | ||
opacity: ${(props) => | ||
props.nightPercentage === 0 || props.nightPercentage === 100 ? '0' : '1'}; | ||
background: #ffffff; | ||
left: calc(${(props) => props.nightPercentage}% - 50px); | ||
bottom: calc( | ||
${(props) => | ||
(1 / 125) * | ||
(-(props.nightPercentage - 50) * (props.nightPercentage - 50)) + | ||
70}% | ||
// parabola formula to get the moon to move in a parabola | ||
); | ||
border-radius: 50%; | ||
filter: blur(5px); | ||
`; | ||
|
||
const ParallaxDiv = styled.div<{ x: number; y: number }>` | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
transform: translate( | ||
${(props) => -props.x * 0.09}px, | ||
${(props) => -props.y * 0.09}px | ||
); | ||
`; | ||
|
||
export const Moon = ({ nightPercentage }: MoonProps) => { | ||
const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); | ||
const [stars, setStars] = useState<React.JSX.Element[]>([]); | ||
|
||
useEffect(() => { | ||
const handleMouseMove = (event) => { | ||
setMousePos({ x: event.clientX, y: event.clientY }); | ||
}; | ||
|
||
window.addEventListener('mousemove', handleMouseMove); | ||
|
||
return () => { | ||
window.removeEventListener('mousemove', handleMouseMove); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
setStars(generateStars(120)); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<BackgroundDiv nightPercentage={nightPercentage} /> | ||
<ParallaxDiv x={mousePos.x} y={mousePos.y}> | ||
{nightPercentage === 0 || nightPercentage === 100 ? '' : stars} | ||
</ParallaxDiv> | ||
<MoonDiv nightPercentage={nightPercentage} /> | ||
</> | ||
); | ||
}; |
20 changes: 0 additions & 20 deletions
20
src/components/content/heroes/aurora/weather-easter-egg/sun-percentage-calculator.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/components/content/heroes/aurora/weather-easter-egg/sun.test.ts
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
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