Skip to content

Commit

Permalink
feat: add randomized rotations and hover pointer cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronchan32 committed Apr 5, 2024
1 parent 37681dc commit e2a7a03
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
8 changes: 4 additions & 4 deletions public/images/cursor-pointer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions public/images/cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions src/components/Asteroid/Asteroid.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
.asteroid-container {
position: absolute;
position: fixed;
height: 100%;
width: 100%;
display: grid;
align-items: start;
pointer-events: none;

.asteroid {
z-index: 100;
z-index: 2;
position: absolute;
top: 0;
left: 0;
pointer-events: auto;

&:hover {
cursor: $cursor-pointer;
}
}

.fragment {
Expand Down
11 changes: 11 additions & 0 deletions src/components/Asteroid/Asteroid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Asteroid({ homeRef }: AsteroidProps) {
const [asteroidVisibility, setAsteroidVisibility] = useState<boolean[]>([]);
const [asteroidExploded, setAsteroidExploded] = useState<boolean[]>([]);
const [fragmentEdPts, setFragmentEndPts] = useState<Point[]>([]);
const [asteroidRotations, setAsteroidRotations] = useState<number[]>([]);

type animationProps = {
initial: Point;
Expand Down Expand Up @@ -145,6 +146,15 @@ export default function Asteroid({ homeRef }: AsteroidProps) {
}
}, [homeRef, contentInfo.paddingLeft, contentInfo.width]);

// Initialize asteroid rotation values
useEffect(() => {
const rotations = Array.from(
{ length: numAsteroids },
() => Math.random() * 360
);
setAsteroidRotations(rotations);
}, [numAsteroids]);

return (
<section className="asteroid-container">
{Array.from({ length: numAsteroids }, (_, index) =>
Expand Down Expand Up @@ -195,6 +205,7 @@ export default function Asteroid({ homeRef }: AsteroidProps) {
initial={asteroidAnimations[index]?.initial}
animate={asteroidAnimations[index]?.animate}
transition={asteroidAnimations[index]?.transition}
style={{ rotate: `${asteroidRotations[index]}deg` }}
>
<LargeAsteroid2 />
</motion.div>
Expand Down

0 comments on commit e2a7a03

Please sign in to comment.