Skip to content

Commit

Permalink
Add color names (not ideal, but something to start with at least)
Browse files Browse the repository at this point in the history
  • Loading branch information
andbas committed Sep 19, 2024
1 parent d867d55 commit 1a0a6ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"color-2-name": "^1.4.4",
"lucide-react": "^0.441.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
5 changes: 4 additions & 1 deletion src/components/video-feed.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState, MouseEvent } from "react";
import { Button } from "./ui/button";
import { SwitchCamera } from "lucide-react";
import { closest } from "color-2-name";

function VideoFeed() {
const videoRef = useRef<HTMLVideoElement | null>(null);
Expand Down Expand Up @@ -52,7 +53,8 @@ function VideoFeed() {
1,
1
).data;
const color = `rgb(${pixelData[0]}, ${pixelData[1]}, ${pixelData[2]})`;
let [r, g, b] = pixelData;
const color = `rgb(${r}, ${g}, ${b})`;
setPixelColor(color);
}
}
Expand Down Expand Up @@ -119,6 +121,7 @@ function VideoFeed() {
Pixel Coordinates: ({coordinates.x}, {coordinates.y})
</p>
<p className="mt-2">Pixel Color: {pixelColor}</p>
<p className="mt-2">Closest: {`${closest(pixelColor).name}`}</p>
</div>
</div>
);
Expand Down

0 comments on commit 1a0a6ad

Please sign in to comment.