1.0.0 • Published 3 years ago

react-pencil.js v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

react-pencil.js logo

react-pencil.js

Pencil.js ❤️ React - Build reactive 2D graphics scene in your React project

Installation

npm install react-pencil.js

You need to install react (certainly with react-dom) and pencil.js yourself alongside react-pencil.js.

Usage

1. NPM (recommended)

You will need a compiler (webpack, rollup ...) configured with Babel to bundle it. Look at the example to know how.

import React from "react";
import ReactDOM from "react-dom";
import ReactPencil from "react-pencil.js";

const { PScene, PCircle } = ReactPencil;

function App () {
    return <PScene>
        <PCircle  radius={100} />
    </PScene>;
}

ReactDOM.render(
    <App />,
    document.getElementById("root"),
);

2. Direct <script> tag

For prototyping or when you don't have access to NPM. Look at the example for a slightly more in-depth demo.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example</title>
</head>
<body>
<!-- React and ReactDOM script tag -->
<!-- Switch these to "production.min.js" when deploying -->
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
<!-- Pencil.js script tag -->
<script src="https://unpkg.com/pencil.js"></script>
<!-- react-pencil.js script tag -->
<script src="https://unpkg.com/react-pencil.js"></script>
<script>
    const { PScene, PCircle } = ReactPencil;

    ReactDOM.render(
        React.createElement(PScene, null,
            React.createElement(PCircle, {
                position: [200, 200],
                radius: 100,
                options: {
                    fill: "red",
                },
                draggable: true,
            }),
        ),
        document.body,
    );
</script>
</body>
</html>

License

MIT

1.0.0

3 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago