1.0.5 • Published 5 months ago

react-altdraw v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

FeatureDescriptionStatus
backgroundSet the background color
fillSet the fill color
strokeSet the stroke color
strokeWeightSet the stroke weight
noFillDisable fill
noStrokeDisable stroke
arcDraw an arc
ellipseDraw an ellipse
circleDraw a circle
lineDraw a line
rectDraw a rectangle
triangleDraw a triangle
quadDraw a quadrilateral, a four sided polygon
Curves and bezierDraw curves and bezier curves
TypographyDraw text on the canvas
mapRe-maps a number from one range to another
distCalculate the distance between two points
noiseGenerate a value between 0 and 1
Vector manipulationAdd, subtract, multiply, divide, and more
contextdraw on 2d context it manually
width and heightThe width and height of the canvas
mouseX and mouseYHorizontal and vertical position of the mouse
pmouseX and pmouseYPrevious horizontal and vertical position of the mouse
mouseIsPressedTrue if the mouse is pressed
mouseButtonThe current state of the mouse button
mouseWheelThe amount the mouse wheel has moved
keyThe value of the most recent key pressed
keyCodeThe value of the most recent key pressed
keyIsPressedTrue if a key is pressed
frameCountThe number of frames displayed
frameRateThe number of frames displayed per second
saveSave the canvas as an image
fullscreenSet the canvas to fullscreen
TransformationsTranslate, rotate, scale, and more
Image manipulationLoad, 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.

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago