npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-altdraw

v1.0.3

Published

A react component for drawing in things on a canvas

Downloads

38

Readme

Simple react component library to draw some basic shapes using canvas. inspired by p5.js and react-p5

:warning: This is a work in progress: This library is not ready for production use yet.

Example

import Draw from 'react-altdraw';

function App() {
  return (
    <Draw
      setup={(canvas) => {
        canvas.width = 300;
        canvas.height = 300;
      }}
      draw={(dc) => {
        dc.background('gray');
        dc.fill('white');
        const x = dc.windowWidth / 2;
        const y = dc.windowHeight / 2;
        const r = Math.abs(Math.sin(dc.frameCount / 100)) * 100;
        dc.circle(x, y, r);
        dc.text(`frameRate: ${dc.frameRate}`, 10, 20, 20, 'monospace');
      }}
    />
  );
}

Implemented shapes and features

| Feature | Description | Status | | ----------------------- | ------------------------------------------------------ | ------ | | background | Set the background color | ✅ | | fill | Set the fill color | ✅ | | stroke | Set the stroke color | ✅ | | strokeWeight | Set the stroke weight | ✅ | | noFill | Disable fill | ✅ | | noStroke | Disable stroke | ✅ | | arc | Draw an arc | ✅ | | ellipse | Draw an ellipse | ✅ | | circle | Draw a circle | ✅ | | line | Draw a line | ✅ | | rect | Draw a rectangle | ✅ | | triangle | Draw a triangle | ✅ | | quad | Draw a quadrilateral, a four sided polygon | ✅ | | Curves and bezier | Draw curves and bezier curves | ❌ | | Typography | Draw text on the canvas | ✅ | | map | Re-maps a number from one range to another | ✅ | | dist | Calculate the distance between two points | ✅ | | noise | Generate a value between 0 and 1 | ✅ | | Vector manipulation | Add, subtract, multiply, divide, and more | ❌ | | context | draw on 2d context it manually | ✅ | | width and height | The width and height of the canvas | ✅ | | mouseX and mouseY | Horizontal and vertical position of the mouse | ✅ | | pmouseX and pmouseY | Previous horizontal and vertical position of the mouse | ✅ | | mouseIsPressed | True if the mouse is pressed | ✅ | | mouseButton | The current state of the mouse button | ✅ | | mouseWheel | The amount the mouse wheel has moved | ❌ | | key | The value of the most recent key pressed | ✅ | | keyCode | The value of the most recent key pressed | ✅ | | keyIsPressed | True if a key is pressed | ✅ | | frameCount | The number of frames displayed | ✅ | | frameRate | The number of frames displayed per second | ✅ | | save | Save the canvas as an image | ❌ | | fullscreen | Set the canvas to fullscreen | ❌ | | Transformations | Translate, rotate, scale, and more | ❌ | | Image manipulation | Load, display, and manipulate images | ❌ |

Notes

  • This library is not intended to replace p5.js, it's just a simple alternative for react developers who want to draw shapes using canvas.

  • This library will not support webgl, sound, or any other feature that is not related to drawing shapes on a canvas or user interaction. This is a design decision to keep the library simple and focused.

  • This library is not intended to be a 1:1 copy of p5.js, some features may be missing or implemented differently.

  • This library is not intended to be a general purpose canvas library, it's just for drawing shapes and user interaction.