sticknodes-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

sticknodes-js

This is the JavaScript/TypeScript bindings for sticknodes-rs. It allows manipulation of Stick Nodes Stickfigures from within a web or Node.js environment.

Installation

To install via NPM:

npm install sticknodes-js

Usage

In Node.js or Bundlers (e.g., Webpack, Rollup, Parcel)

import { Stickfigure, NodeType, Color } from "sticknodes-js";

const stickfigure = new Stickfigure();
const rootNode = stickfigure.get_node(0)
const ball = rootNode.add_child({node_type: NodeType.Circle, length: 100, local_angle: 0, color: Color.from_hex("#000000")});
const ball2 = rootNode.add_child({node_type: NodeType.Circle, length: 100, local_angle: 180, color: Color.from_hex("#000000")});
const shaft = rootNode.add_child({node_type: NodeType.RoundedSegment, length: 200, local_angle: 90, thickness: 100, color: Color.from_hex("#000000")});
const obj = stickfigure.to_jsobject(); 
console.log(JSON.stringify(obj, undefined, 1));

In the Browser (Web)

<script type="module">
    import init, * as sn from "https://cdn.jsdelivr.net/npm/sticknodes-js@1.0.10/sticknodes_js_web.js";

    init().then(() => {
        const stickfigure = new sn.Stickfigure();
        const rootNode = stickfigure.get_node(0)
        rootNode.add_child({node_type: sn.NodeType.Circle, length: 100, local_angle: 0, color: sn.Color.from_hex("#000000")});
        rootNode.add_child({node_type: sn.NodeType.Circle, length: 100, local_angle: 180, color: sn.Color.from_hex("#000000")});
        rootNode.add_child({node_type: sn.NodeType.RoundedSegment, length: 200, local_angle: 90, thickness: 100, color: sn.Color.from_hex("#000000")});
        const obj = stickfigure.to_jsobject(); 
        console.log(JSON.stringify(obj, undefined, 1));
    });
</script>

Documentation

Auto generated, detailed docs can be found here.

TypeScript Definitions

The library includes TypeScript definitions to ensure smooth integration with TypeScript projects.

License

MIT License - See LICENSE

Package Sidebar

Install

npm i sticknodes-js

Weekly Downloads

41

Version

1.0.10

License

MIT

Unpacked Size

891 kB

Total Files

13

Last publish

Collaborators

  • vincetheprogrammer