Skip to content

Run React.js code on pixelated displays, with a lightweight custom renderer

Notifications You must be signed in to change notification settings

hi019/react-pixel-renderer

Repository files navigation

This is a custom React renderer designed to render to a pixelated display. The project is not coupled to any specific host environment, it uses an interface to draw. The interface looks like this:

interface Driver {
    drawText(text: string, x: number, y: number, color: string): void;
    drawPixel(x: number, y: number, color: string): void;
    // Get the height and width of some text
    stringDimensions(text: string): { width: number; height: number };
    
    init(): void;
    // Clear the entire display
    clear(): void;

    // Display height and width
    width: number;
    height: number;
}

Two driver interfaces are provided: one for a Pi-powered Adafruit LED Matrix and another for browser canvas. Also, a Flexbox implementation is provided, based on Yoga. There are examples in playground/.

Demo

const convertDate = (date: Date): string => {
  return format(utcToZonedTime(date, "America/Indianapolis"), "h:mm:ss a");
};

function App() {
  const [time, setTime] = useState(convertDate(new Date()));

  useEffect(() => {
    const interval = setInterval(() => {
      setTime(convertDate(new Date()));
    }, 1000);

    return () => clearInterval(interval);
  }, [setTime]);

  return (
    <Flex justifyContent={"center"} alignItems={"center"}>
      <Text color={"orange"}>{time}</Text>
      <Text color={"orange"}>Testing again</Text>
    </Flex>
  );
}
CleanShot 2024-11-25 at 19 02 23@2x

Resources

About

Run React.js code on pixelated displays, with a lightweight custom renderer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published