Created
August 30, 2022 15:51
-
-
Save bananu7/7941fbcaa3950f86df2ef99062a6600c to your computer and use it in GitHub Desktop.
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
const Hex = (props) => { | |
const canvasRef = React.useRef(null); | |
React.useEffect(() => { | |
const a = (2 * Math.PI) / 6; | |
const r = 40; | |
const canvas = canvasRef.current; | |
const ctx = canvas.getContext("2d"); | |
const x = 40; | |
const y = 40; | |
ctx.clearRect(0, 0, canvas.width, canvas.height); | |
ctx.strokeStyle = "rgba(255, 0, 0, 1)"; | |
ctx.beginPath(); | |
for (var i = 0; i < 6; i++) { | |
ctx.lineTo(x + r * Math.cos(a * i), y + r * Math.sin(a * i)); | |
} | |
ctx.closePath(); | |
ctx.stroke(); | |
}, []); | |
const style = { | |
position: "absolute", | |
left: props.x, | |
top: props.y | |
}; | |
return <canvas ref={canvasRef} style={style} {...props} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment