-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
963 additions
and
1 deletion.
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
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,50 @@ | ||
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; | ||
|
||
const ColorMap = { | ||
0: "#FFFFFF", // WHITE | ||
1: "#000000", // BLACK | ||
2: "#FF0000", // RED | ||
3: "#00FF00", // GREEN | ||
4: "#0000FF", // BLUE | ||
5: "#FFFF00", // YELLOW | ||
6: "#800080", // PURPLE | ||
7: "#FFA500", // ORANGE | ||
}; | ||
|
||
const PixelCanvas = () => { | ||
const { data: canvasData } = useScaffoldReadContract({ | ||
contractName: "PixelCanvas", | ||
functionName: "getFullCanvas", | ||
watch: true, | ||
}); | ||
|
||
if (!canvasData?.length) { | ||
return <div className="animate-pulse">Loading canvas...</div>; | ||
} | ||
|
||
const width = canvasData.length; | ||
const height = canvasData[0].length; | ||
|
||
return ( | ||
<div | ||
className="grid gap-0 border border-base-300" | ||
style={{ gridTemplateColumns: `repeat(${height}, minmax(0, 1fr))` }} | ||
> | ||
{Array.from({ length: height }, (_, y) => | ||
Array.from({ length: width }, (_, x) => { | ||
const pixel = canvasData[x][y]; | ||
return ( | ||
<div | ||
key={`${x}-${y}`} | ||
className="w-3 h-3 cursor-pointer outline-white hover:outline hover:z-10 hover:brightness-90" | ||
style={{ backgroundColor: ColorMap[pixel.color as keyof typeof ColorMap] }} | ||
title={`Author: ${pixel.author}\nTimestamp: ${new Date(Number(pixel.timestamp) * 1000).toLocaleString()}`} | ||
/> | ||
); | ||
}), | ||
).flat()} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PixelCanvas; |
Oops, something went wrong.