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

gl-line-drawer

v1.0.0

Published

A simple line drawer using webgl

Downloads

5

Readme

gl-line-drawer

This is a simple 2D line drawer package using WebGL. Due to the restriction of WebGL, gl.LINES drawing type only supports 1px line. Thus, it needs to be created by augmenting the single point to mutiple points to generate triangles forming a line.

This package enables you to pass points coordinates and expected transform matrix to generate line. It supports drawing line with optional caps and colors. You can also set the maximum miter length to avoid unexpected mitters at the bend.

Installing

npm install gl-line-drawer

Usage

You can refere the code in folder demo to see more details

import { LineDrawer } from '';

const canvas = document.getElementById('yourCanvasElement');
const gl = canvas.getContext('webgl2');
const points = [
    [-0.9, 0.0],
    [-0.8, -0.3],
    [-0.6, 0.2],
    [-0.4, -0.5],
    [0.0, 0.0],
    [0.2, 0.2],
    [0.4, -0.4],
    [0.6, 0.4],
];

// First you need to generate an instance of line drawer with options
const lineDrawer = new LineDrawer({
    gl,
    points,
    color: [0.5, 0.5, 0.5],
});

// Then in the each animation frame pass the transform marix for rendering, the default value is an identity matrix
const renderer = () => {
    // Pass the transform matrix to line drawer
    lineDrawer.render();
    requestAnimationFrame(renderer);
};
        
// Start render
renderer();

There are following options you can set:

{
    /**
     * The gl context
     */
    gl: WebGLRenderingContext | WebGL2RenderingContext;
    /**
     * 2-dimensional points array 
     */
    points: number[][];
    /**
     * The resolution of devices
     * Default value: calculate based on your canvas property
     */
    resolution?: number[];
    /**
     * Line width
     * Default value: 10px
     */
    lineWidth?: number;
    /**
     * Max miter length
     * Default value: 20px
     */
    maxMiterLength?: number;
    /**
     * Line color with array of rgb
     * Default value: [0., 0., 0.]
     */
    color?: number[];
    /**
     * Cap color with array of rgb
     * Only works when you set cap style
     * Default value: [0., 0., 0.]
     */
    capColor?: number[];
    /**
     * Cap style enabling round, circle or nothing
     * Default value: undefined
     */
    capStyle?: 'round' | 'circle';
}

Furture Work

  • Support setting texture for lines
  • Support mutiple lines