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

drcircuitscanvaslibrary

v1.5.2

Published

A small library to make it easier to draw on HTML5 canvases

Downloads

46

Readme

DrCircuitsCanvasLibrary click to view examples live

A tiny library for doing boilerplate stuff for canvas based vanilla js gfx and game projects.

Installation: Install via npm: npm install --save drcircuitscanvaslibrary

Usage:

(function(){
    let scr;
  
    function setup() {
        scr = dcl.setupScreen(window.innerWidth ,window.innerHeight );
        scr.setBgColor('darkblue');
        document.body.style.backgroundColor = 'darkblue';      
    }
    function draw(t, dt){
       // your drawing and update logic here..
    }
    dcl.init(setup, draw);
    dcl.animate();
})();

Examples:

setupScreen function

setupScreen: function (width, height, keepSquare, gridScale)

Parameters:

  • width: The width of your canvas
  • height: The height of your canvas
  • keepSquare: This will create a square canvas
  • gridScale: Create a grid based coordinate system, where the scale is number of square pixels in one grid unit.

return object:

This method returns an object with the following:

  • ctx: 2d rendering context
  • width: the width of the canvas
  • height: the height of the canvas
  • cols: the number of columns in your grid
  • rows: the number of rows in your grid
  • setBgColor: function(color): sets the background color of the canvas
  • randomSpot: function(): retrieves a random spot from the grid, returns a vector x, y

dcl.random function

dcl.random: function(min, max)

Parameters:

  • min: the minimum desired number of the random range. & max: the maximum desired number of the random range.

return object:

This method returns a random integer between the given min / max values passed to the function.

dcl.rect function

dcl.rect: function(x, y, width, height, color, lineWidth, lineColor, ctx)

Parameters:

  • x: the x position of the upper left corner of the rectangle
  • y: the y position of the upper left corner of the rectangle
  • width: the width of the rectangle
  • height: the height of the rectangle, if 0 or no value is provided, a square with a side length equal to the "width" parameter will be drawn
  • color: the fill color of the rectangle, defaults to "blue" if no input is given.
  • lineWidth: The width of the stroke around the perimeter : optional
  • lineColor: The color of the stroke around the perimeter, defaults to "#000088" if no input is given : optional
  • ctx: The canvas context to draw the circle on : optional.

void

This method draws a rectangle based on the given parameters.

dcl.circle function

dcl.circle: function(x, y, radius, color, lineWidth, lineColor, ctx)

Parameters:

  • x: the x position of the center of the circle
  • y: the y position of the center of the circle
  • radius: the radius of the circle
  • color: the fill color of the circle, defaults to "blue" if no input is given.
  • lineWidth: The width of the stroke around the perimeter : optional
  • lineColor: The color of the stroke around the perimeter, defaults to "#000088" if no input is given : optional
  • ctx: The canvas context to draw the circle on : optional.

void

This method draws a circle based on the given parameters.

dcl.line function

dcl.circle: function(x, y, dx, dy, lineWidth, lineColor, ctx)

Parameters:

  • x: the x position of the start of the line
  • y: the y position of the start of the line
  • dx: the x position of the end of the line
  • dy: the y position of the end of the line
  • lineWidth: The width of the stroke around the perimeter : optional
  • lineColor: The color of the stroke around the perimeter, defaults to "#000088" if no input is given : optional
  • ctx: The canvas context to draw the circle on : optional.

void

This method draws a line based on the given parameters.

dcl.init function

Parameters:

  • setup a function to setup your scene
  • draw a function that will run in a loop rendering your scene

dcl.animate function

This function starts the render loop.