# @react-canvas-animation/core

> A p5js inspired library for creating canvas animations in react

Latest version **0.1.5** (published 2021-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install @react-canvas-animation/core
pnpm add @react-canvas-animation/core
yarn add @react-canvas-animation/core
bun add @react-canvas-animation/core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2021-04-18 |
| First published | 2020-05-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Befeepilf |
| Maintainers | befeepilf |

## Links

- npm: https://www.npmjs.com/package/@react-canvas-animation/core
- Repository: https://github.com/Befeepilf/react-canvas-animation
- Homepage: https://github.com/Befeepilf/react-canvas-animation#readme
- Issues: https://github.com/Befeepilf/react-canvas-animation/issues
- npm.io page: https://npm.io/package/@react-canvas-animation/core

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.13.1

## Recent versions

- 0.1.5 (latest) — 2021-04-18
- 0.1.4 — 2020-07-25
- 0.1.3 — 2020-07-25
- 0.1.2 — 2020-07-25
- 0.1.1 — 2020-05-27
- 0.1.0 — 2020-05-27
- 0.0.26 — 2020-05-27
- 0.0.25 — 2020-05-27
- 0.0.24 — 2020-05-27
- 0.0.23 — 2020-05-27
- 0.0.22 — 2020-05-27
- 0.0.21 — 2020-05-27
- 0.0.20 — 2020-05-27
- 0.0.19 — 2020-05-27
- 0.0.18 — 2020-05-27
- … 14 more at https://npm.io/package/@react-canvas-animation/core/versions

## README

# React Canvas Animation

[![Build Status](https://travis-ci.org/Befeepilf/react-canvas-animation.svg?branch=master)](https://travis-ci.org/Befeepilf/react-canvas-animation) [![Maintainability](https://api.codeclimate.com/v1/badges/e95739067748d8f0ab75/maintainability)](https://codeclimate.com/github/Befeepilf/react-canvas-animation/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e95739067748d8f0ab75/test_coverage)](https://codeclimate.com/github/Befeepilf/react-canvas-animation/test_coverage)

## Package structure

- **@react-canvas-animation/core**
  - contains the `Canvas` component
- **@react-canvas-animation/draw**
  - contains helper functions to simplify creation of sketches
  - depends on *@react-canvas-animation/core*
- **@react-canvas-animation/math**
  - contains a bunch of math functions
  - totally independent of the other packages
- **@react-canvas-animation/vector**
  - implements vectors and vector related functions
  - totally independent of the other packages

## Installation

```
// with npm
npm i --save @react-canvas-animation/core @react-canvas-animation/draw

// with yarn
yarn add @react-canvas-animation/core @react-canvas-animation/draw
```

## Usage

Here is a quick example to get you started:
```js
import Canvas from '@react-canvas-animation/core';;
import '@react-canvas-animation/draw';

const mySketch = ({width, height, fill, circle}) => {
  fill('red');
  circle(width / 2, height / 2, 50);
};

function App() {
  return <Canvas sketch={mySketch}/>;
}
```

### Canvas component

#### Props

| Name    | Type      | Default            | Description   |
| ------- | --------- | ------------------ | ------------- |
| sketch  | function  |                    | This function is called for every frame of the animation. It should contain the drawing logic.<br>**Signature**:<br/> `function(draw: object) => void`<br/>*draw*: A reference to the context of the Canvas component (*not* the context of the canvas element) |
| width   | number    | window.innerWidth  | Width of the canvas in pixel |
| height  | number    | window.innerHeight | Height of the canvas in pixel  |

#### The sketch function
This function takes one argument which is a reference to the context of the corresponding Canvas component (not to be confused with the context of the canvas *element*). The context contains properties of the canvas such as its width and height as well as drawing methods if `@react-canvas-animation/draw` was imported. Since the sketch function shares the same context with the Canvas component (given that it is *not* an arrow function), all these methods and properties are also accessible via `this`.

##### Available canvas properties:

| Name    | Type    | Description       |
| ------- | ------- | ----------------- |
| width   | number  | Width of the canvas  |
| height  | number  | Height of the canvas |
| ctx     | object  | Context of the canvas *element*  |
| frameCount   | number | The number of times the sketch function has been called  |

#### Responsiveness
If no width and height are given then the component handles window resizes on its own and updates the width and height. So if you want to create a responsive sketch don't provide the width and height prop and construct your sketch function in such a way that positions and sizes are not hardcoded but depend on the `width` and `height` properties of the Canvas component.

---
_Source: https://npm.io/package/@react-canvas-animation/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
