-
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.
separated files to clean up page.tsx, fixed some hovering issues
- Loading branch information
Showing
4 changed files
with
137 additions
and
116 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { GRID_CONFIG } from "../constants/gridConfig"; | ||
import { GridItem } from "../utils/types"; | ||
import { motion } from "framer-motion"; | ||
import Image from "next/image"; | ||
import React from "react"; | ||
|
||
interface CircleProps { | ||
circle: GridItem; | ||
mousePosition: { x: number; y: number }; | ||
onPress: (circle: GridItem) => void; | ||
} | ||
|
||
const Circle = React.memo(({ circle, mousePosition, onPress }: CircleProps) => { | ||
const circleCenter = { | ||
x: circle.x + GRID_CONFIG.RADIUS / 2, | ||
y: circle.y + GRID_CONFIG.RADIUS / 2, | ||
}; | ||
|
||
const distanceFromMouse = Math.sqrt( | ||
Math.pow(circleCenter.x - mousePosition.x, 2) + | ||
Math.pow(circleCenter.y - mousePosition.y, 2), | ||
); | ||
|
||
const scale = | ||
distanceFromMouse < GRID_CONFIG.ZOOM_ZONE_SIZE / 2 | ||
? 1 + | ||
(GRID_CONFIG.CENTER_ZOOM - 1) * | ||
Math.max(1 - distanceFromMouse / (GRID_CONFIG.ZOOM_ZONE_SIZE / 2)) | ||
: 1; | ||
|
||
return ( | ||
<motion.div | ||
onClick={() => onPress(circle)} | ||
style={{ | ||
position: "absolute", | ||
left: circle.x, | ||
top: circle.y, | ||
width: GRID_CONFIG.RADIUS, | ||
height: GRID_CONFIG.RADIUS, | ||
borderRadius: "50%", | ||
overflow: "visible", | ||
transform: `scale(${scale})`, | ||
transformOrigin: "center center", | ||
willChange: "transform", | ||
}} | ||
whileHover={{ | ||
transition: { duration: 0.2 }, | ||
}} | ||
> | ||
<div className="w-full h-full cursor-pointer relative"> | ||
{circle.image ? ( | ||
<div className="w-full h-full rounded-full"> | ||
<Image | ||
src={circle.image} | ||
alt={circle.name} | ||
width={GRID_CONFIG.RADIUS} | ||
height={GRID_CONFIG.RADIUS} | ||
className="rounded-full" | ||
/> | ||
</div> | ||
) : ( | ||
<div | ||
className="w-full h-full rounded-full" | ||
style={{ backgroundColor: circle.color }} | ||
/> | ||
)} | ||
</div> | ||
</motion.div> | ||
); | ||
}); | ||
|
||
Circle.displayName = "Circle"; | ||
export default Circle; |
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,9 @@ | ||
export const GRID_CONFIG = { | ||
RADIUS: 60, | ||
CENTER_ZOOM: 1.3, | ||
ZOOM_ZONE_SIZE: 500, | ||
SPACING: 42, // 60 * 0.7 | ||
HEX_RATIO: Math.sqrt(3) / 2, | ||
COLORS: ["#0A0A0A"], | ||
DECORATIVE_CIRCLES: 400, | ||
}; |
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,37 @@ | ||
import { GRID_CONFIG } from "../constants/gridConfig"; | ||
|
||
export const generateHoneycombPositions = ( | ||
totalItems: number, | ||
width: number, | ||
height: number, | ||
) => { | ||
const positions = []; | ||
const hexWidth = GRID_CONFIG.SPACING * 2; | ||
const hexHeight = hexWidth * GRID_CONFIG.HEX_RATIO; | ||
const ringsNeeded = Math.ceil(Math.sqrt(totalItems / 3)) + 2; | ||
|
||
for (let q = -ringsNeeded; q <= ringsNeeded; q++) { | ||
for (let r = -ringsNeeded; r <= ringsNeeded; r++) { | ||
const x = hexWidth * (q + r / 2); | ||
const y = hexHeight * r; | ||
|
||
if (Math.abs(q) + Math.abs(r) + Math.abs(-q - r) <= 2 * ringsNeeded) { | ||
positions.push({ | ||
x: width / 2 + x, | ||
y: height / 2 + y, | ||
}); | ||
} | ||
} | ||
} | ||
return positions | ||
.sort((a, b) => { | ||
const distA = Math.sqrt( | ||
Math.pow(a.x - width / 2, 2) + Math.pow(a.y - height / 2, 2), | ||
); | ||
const distB = Math.sqrt( | ||
Math.pow(b.x - width / 2, 2) + Math.pow(b.y - height / 2, 2), | ||
); | ||
return distA - distB; | ||
}) | ||
.slice(0, totalItems); | ||
}; |